Overview
The Code Generation use cases leverage Roslyn to automatically generate and modify C# code following Clean Architecture patterns.
AddApiControllerUseCase
Adds a new controller method to the API layer.
Method Signature
public Result<RollbackManager.RollbackEntry> Execute(
string projectPath,
string moduleName,
string operation,
string methodName,
RollbackManager.RollbackEntry? rollbackEntry = null
)
The root path of the project
Name of the module (e.g., “Users”, “Products”)
HTTP operation type (e.g., “GET”, “POST”, “PUT”, “DELETE”)
Name of the method to generate
rollbackEntry
RollbackManager.RollbackEntry
Optional rollback entry for tracking changes
Result<RollbackManager.RollbackEntry>
Result<RollbackManager.RollbackEntry>
Result containing a rollback entry for undo operations
True if the controller method was added successfully
Data
RollbackManager.RollbackEntry
Rollback information for reverting the changes
Error message if the operation failed
Example Usage
var useCase = new AddApiControllerUseCase();
var result = useCase.Execute(
projectPath: "C:\\Projects\\MyApp",
moduleName: "Users",
operation: "POST",
methodName: "CreateUser"
);
if (result.IsSuccess)
{
Console.WriteLine("API Controller method added");
}
AddApiEndpointUseCase
Adds a minimal API endpoint to the API layer.
Method Signature
public Result<RollbackManager.RollbackEntry> Execute(
string projectPath,
string moduleName,
string operation,
string methodName,
RollbackManager.RollbackEntry? rollbackEntry = null,
bool includeAppLayer = false
)
The root path of the project
Name of the endpoint method
rollbackEntry
RollbackManager.RollbackEntry
Optional rollback entry
Whether to also generate the Application layer method
Result<RollbackManager.RollbackEntry>
Result<RollbackManager.RollbackEntry>
Result containing a rollback entry
Example Usage
var useCase = new AddApiEndpointUseCase();
var result = useCase.Execute(
projectPath: "C:\\Projects\\MyApp",
moduleName: "Products",
operation: "GET",
methodName: "GetProduct",
includeAppLayer: true
);
AddApplicationMethodUseCase
Adds a use case method to the Application layer.
Method Signature
public Result<RollbackManager.RollbackEntry> Execute(
string projectPath,
string moduleName,
string operation,
string methodName,
RollbackManager.RollbackEntry? rollbackEntry = null,
bool useGenericRepository = false
)
The root path of the project
Operation type (e.g., “Create”, “Update”, “Delete”, “Get”)
Name of the use case method
rollbackEntry
RollbackManager.RollbackEntry
Optional rollback entry
Whether to use a generic repository pattern
Result<RollbackManager.RollbackEntry>
Result<RollbackManager.RollbackEntry>
Result containing a rollback entry
Example Usage
var useCase = new AddApplicationMethodUseCase();
var result = useCase.Execute(
projectPath: "C:\\Projects\\MyApp",
moduleName: "Orders",
operation: "Create",
methodName: "CreateOrder",
useGenericRepository: true
);
if (result.IsSuccess)
{
Console.WriteLine("Application layer method added");
}
AddDomainMethodUseCase
Adds a method to the Domain layer entity or service.
Method Signature
public async Task<Result<RollbackManager.RollbackEntry>> ExecuteAsync(
string projectPath,
string moduleName,
string operation,
string methodName,
RollbackManager.RollbackEntry? rollbackEntry = null
)
The root path of the project
Name of the domain method
rollbackEntry
RollbackManager.RollbackEntry
Optional rollback entry
Result<RollbackManager.RollbackEntry>
Result<RollbackManager.RollbackEntry>
Result containing a rollback entry
Example Usage
var useCase = new AddDomainMethodUseCase();
var result = await useCase.ExecuteAsync(
projectPath: "C:\\Projects\\MyApp",
moduleName: "Customers",
operation: "Validate",
methodName: "ValidateEmail"
);
AddInfrastructureMethodUseCase
Adds a method to the Infrastructure layer (repositories, services).
Method Signature
public Result<RollbackManager.RollbackEntry> Execute(
string projectPath,
string moduleName,
string operation,
string methodName,
RollbackManager.RollbackEntry? rollbackEntry = null
)
The root path of the project
Name of the infrastructure method
rollbackEntry
RollbackManager.RollbackEntry
Optional rollback entry
Result<RollbackManager.RollbackEntry>
Result<RollbackManager.RollbackEntry>
Result containing a rollback entry
AddDependencyInjectionUseCase
Registers services in the dependency injection container.
Method Signature
public Result Execute(
string projectPath,
string moduleName,
IEnumerable<string> operations
)
The root path of the project
operations
IEnumerable<string>
required
List of operations to register (e.g., [“Create”, “Update”, “Delete”])
Result indicating success or failure
Example Usage
var useCase = new AddDependencyInjectionUseCase();
var operations = new[] { "Create", "Update", "Delete", "Get" };
var result = useCase.Execute(
projectPath: "C:\\Projects\\MyApp",
moduleName: "Invoices",
operations: operations
);
if (result.IsSuccess)
{
Console.WriteLine("Dependency injection configured");
}
GenerateModuleUseCase
Generates a complete module structure following Clean Architecture.
Method Signature
public async Task<Result> ExecuteAsync(
string projectDirectory,
string moduleNames,
string dbChoice
)
The root directory of the project
Semicolon-separated list of module names (e.g., “Users;Products;Orders”)
Database choice: “S” for Sybase, “P” for Postgres
Result indicating success or failure
Example Usage
var useCase = new GenerateModuleUseCase(moduleGeneratorService);
var result = await useCase.ExecuteAsync(
projectDirectory: "C:\\Projects\\MyApp",
moduleNames: "Users;Products;Orders",
dbChoice: "P"
);
if (result.IsSuccess)
{
Console.WriteLine("Modules generated successfully");
}
Process Flow
- Parses the semicolon-separated module names
- For each module:
- Creates Domain entities
- Creates Application use cases
- Creates Infrastructure repositories
- Creates API endpoints
- Configures dependency injection
- Uses the specified database provider (Sybase or Postgres)