Overview
The Module Generator Service creates complete module scaffolding across multiple architectural layers (API, Application, Domain, Infrastructure) with support for both Ardalis Endpoints and Classic Controller patterns. Interface:IModuleGeneratorServiceImplementation:
ModuleGeneratorServiceNamespace:
Chapi.Infrastructure.Services
Interface Definition
IModuleGeneratorService
Methods
GenerateModuleAsync
Generates a complete module with default CRUD operations (Get, Post, GetById) across all architectural layers.The root directory of the project where the module will be generated
The name of the module to generate (will be capitalized automatically)
The database context name for infrastructure layer integration
Architecture Detection
The service automatically detects the project architecture style:- Ardalis (Endpoints): If an
Endpointsfolder exists in the API project - Classic (Controllers): If using traditional MVC controller pattern
Generated Structure
For a module named “Product”, the service creates:Directory Structure
Default Operations
The service generates three default CRUD operations:Retrieves all records from the entity collection
Creates a new entity record
Retrieves a single entity by its identifier
Dependency Injection
For Classic architecture, the service automatically registers dependencies inDependencyInjection.cs.
For Ardalis architecture, dependency injection is handled by Scrutor auto-discovery (no manual registration).
Transaction Management
The service usesRollbackManager to ensure atomicity:
Usage Example
Dependencies
The service requires the following dependencies:Used to display progress notifications to the user
Code Generation Helpers
The service uses the following helper classes:FindApiDirectory- Locates the API project directoryAddApiEndpointMethod- Generates Ardalis endpoint filesAddApiControllerMethod- Generates classic controller methodsAddApplicationMethod- Generates application layer handlersAddDomainMethod- Generates domain entities and interfacesAddInfrastructureMethod- Generates repository implementationsAddDependencyInjection- Registers services in DI container
Error Handling
The service throws exceptions in the following cases:- API Project Not Found:
"No se pudo detectar el proyecto API." - Operation Generation Failed:
"Error al generar operacion {operation}: {message}"
Notifications
The service sends notifications during execution:Notes
- Module names are automatically capitalized (e.g., “product” becomes “Product”)
- Ardalis projects use generic repositories by default
- The service creates all necessary directories automatically
- Rollback support ensures clean state on failure