A powerful .NET global tool for generating CQRS (Command Query Responsibility Segregation) pattern code following Clean Architecture principles.
- Command & Query Generation: Generate Command, CommandHandler, Query, and QueryHandler classes
- Validator Generation: Automatically create Command and Query validators
- Request & Response Models: Automatically create Request and Response classes
- API Endpoints: Generate REST API endpoints with proper HTTP methods
- Smart Project Detection: Automatically detect project structure and naming
- Flexible Configuration: Support for custom project names and endpoint controllers
- Clean Architecture: Follows Clean Architecture folder structure conventions
- Modern Architecture: Built with Clean Architecture, Dependency Injection, and SOLID principles
This tool is built using modern software architecture principles:
- Clean Architecture: Separation of concerns with Core, Application, Infrastructure, and Presentation layers
- Dependency Injection: Built-in DI container for better testability and maintainability
- SOLID Principles: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion
- CQRS Pattern: Command Query Responsibility Segregation for better separation of concerns
- Template Engine: Pluggable template system for code generation
dotnet tool install --global AppTo.CodeGen# Generate a command with automatic project detection
codegen add feature QrSale --type command --ep Sale
# Generate a query
codegen add feature GetUser --type query --ep User
# Generate without validator (validator is enabled by default)
codegen add feature Login --type command --validator:false# Specify custom project name
codegen add feature AddCard --type command --ep Card --projectName Metropol.LUKE
# Generate query with custom project name
codegen add feature GetProducts --type query --ep Product --projectName MyCompany.APIWhen you run codegen add feature QrSale --type command --ep Sale, it creates:
Application/
βββ QrSale/
βββ Commands/
βββ QrSaleCommand.cs
βββ QrSaleCommandHandler.cs
βββ QrSaleCommandValidator.cs
Abstraction/
βββ QrSale/
βββ Request/
β βββ QrSaleRequest.cs
βββ Response/
βββ QrSaleResponse.cs
Controllers/
βββ SaleController.cs (endpoint added)
| Option | Description | Example |
|---|---|---|
featureName |
Name of the feature to generate | QrSale |
--type |
Type: command or query |
--type command |
--ep |
Endpoint controller name | --ep Sale |
--projectName |
Custom project name (optional) | --projectName Metropol.LUKE |
--prop-req |
Request property | --prop-req "Name:string,Email:string,Age:int,OrderId:int" |
--prop-resp |
Response property | --prop-resp "Name:string,Email:string,Age:int,OrderId:int" |
--validator |
Validator create (varsayΔ±lan: true) | --validator:false |
# Sadece Request properties
codegen add feature UserRegistration --type command --prop-req "Name:string,Email:string,Age:int,OrderId:int"
# Sadece Response properties
codegen add feature GetUser --type query --prop-resp "Name:string,Email:string,Age:int,OrderId:int"
# Hem Request hem Response properties
codegen add feature CreateProduct --type command --prop-req "Name:string,Price:decimal" --prop-resp "Id:int,Name:string,Price:decimal,CreatedDate:DateTime"
# HiΓ§bir property belirtmezseniz (boΕ sΔ±nΔ±flar)
codegen add feature SimpleCommand --type commandnamespace MyProject.Abstraction.UserRegistration.Request;
public class UserRegistrationRequest
{
public string Name { get; set; }
public string Email { get; set; }
public int Age { get; set; }
public int OrderId { get; set; }
}namespace MyProject.Abstraction.UserRegistration.Response;
public class UserRegistrationResponse
{
public string Name { get; set; }
public string Email { get; set; }
public int Age { get; set; }
public int OrderId { get; set; }
}using MyProject.Infrastructure.CQRS.Concrete;
using MyProject.Abstraction.QrSale.Response;
namespace MyProject.Application.QrSale.Commands;
public class QrSaleCommand : MetropolCommand<QrSaleResponse>
{
// TODO: Add Business Logic here.
}using MyProject.Infrastructure.CQRS.Concrete;
using MyProject.Abstraction.QrSale.Response;
namespace MyProject.Application.QrSale.Commands;
public class QrSaleCommandHandler : MetropolCommandHandler<QrSaleCommand, QrSaleResponse>
{
public override async Task<QrSaleResponse?> Handle(QrSaleCommand request, CancellationToken cancellationToken)
{
// TODO: Add Business Logic here.
return new QrSaleResponse();
}
}using MyProject.Infrastructure.Validation;
namespace MyProject.Application.QrSale.Commands;
public class QrSaleCommandValidator : MetropolValidator<QrSaleCommand>
{
public QrSaleCommandValidator()
{
}
}[HttpPost]
[Route("qr-sale")]
[ProducesResponseType(typeof(MetropolApiResponse<QrSaleResponse>), (int)System.Net.HttpStatusCode.OK)]
public async Task<MetropolApiResponse<QrSaleResponse>> QrSale(
[FromBody] QrSaleRequest request,
CancellationToken cancellationToken)
{
var response = await _cqrsProcessor.ProcessAsync(new QrSaleCommand(), cancellationToken);
return SetResponse(response);
}The tool expects the following folder structure:
YourProject/
βββ src/
β βββ YourProject.Application/
β βββ YourProject.Abstraction/
β βββ YourProject.Controllers/
βββ YourProject.sln
The tool automatically detects your project name using this priority:
- src/ folder: Uses the first directory name in the
src/folder - Manual override: Use
--projectNameparameter to specify custom name
- .NET 9.0 or later
- Clean Architecture project structure
- CQRS pattern implementation
Made with β€οΈ by Batuhan KayaoΔlu