Skip to main content

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
)
projectPath
string
required
The root path of the project
moduleName
string
required
Name of the module (e.g., “Users”, “Products”)
operation
string
required
HTTP operation type (e.g., “GET”, “POST”, “PUT”, “DELETE”)
methodName
string
required
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

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
)
projectPath
string
required
The root path of the project
moduleName
string
required
Name of the module
operation
string
required
HTTP operation type
methodName
string
required
Name of the endpoint method
rollbackEntry
RollbackManager.RollbackEntry
Optional rollback entry
includeAppLayer
bool
default:"false"
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
)
projectPath
string
required
The root path of the project
moduleName
string
required
Name of the module
operation
string
required
Operation type (e.g., “Create”, “Update”, “Delete”, “Get”)
methodName
string
required
Name of the use case method
rollbackEntry
RollbackManager.RollbackEntry
Optional rollback entry
useGenericRepository
bool
default:"false"
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
)
projectPath
string
required
The root path of the project
moduleName
string
required
Name of the module
operation
string
required
Operation type
methodName
string
required
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
)
projectPath
string
required
The root path of the project
moduleName
string
required
Name of the module
operation
string
required
Operation type
methodName
string
required
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
)
projectPath
string
required
The root path of the project
moduleName
string
required
Name of the module
operations
IEnumerable<string>
required
List of operations to register (e.g., [“Create”, “Update”, “Delete”])
Result
Result
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
)
projectDirectory
string
required
The root directory of the project
moduleNames
string
required
Semicolon-separated list of module names (e.g., “Users;Products;Orders”)
dbChoice
string
required
Database choice: “S” for Sybase, “P” for Postgres
Result
Result
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

  1. Parses the semicolon-separated module names
  2. For each module:
    • Creates Domain entities
    • Creates Application use cases
    • Creates Infrastructure repositories
    • Creates API endpoints
    • Configures dependency injection
  3. Uses the specified database provider (Sybase or Postgres)

Build docs developers (and LLMs) love