A lightweight CQRS (Command Query Responsibility Segregation) implementation for .NET projects.
- Simple and clean CQRS pattern implementation
- Request/Response handling with strongly typed interfaces
- Built-in dependency injection integration
- Pipeline behavior support for cross-cutting concerns
- Minimal setup required
dotnet add package Walnut.CQRS.Netservices.AddCQRS();
builder.Services.AddScoped(typeof(IRequestPipeline<,>), typeof(AuthorizationBehaviour<,>));
builder.Services.AddScoped(typeof(IRequestPipeline<,>), typeof(ValidationBehavior<,>));
// Automatically register all IRequestHandler implementations from the current assembly
var assembly = Assembly.GetExecutingAssembly();
builder.Services.Scan(scan => scan
.FromAssemblies(assembly)
.AddClasses(classes => classes.AssignableTo(typeof(IRequestHandler<,>)))
.AsImplementedInterfaces()
.WithTransientLifetime());public class SayHelloCommand : IRequest<string>
{
public string Name { get; set; }
}public class MyController : ControllerBase
{
private readonly IRequestDispatcher _dispatcher;
public MyController(IRequestDispatcher dispatcher)
{
_dispatcher = dispatcher;
}
[HttpPost]
public async Task<string> SayHello([FromBody] SayHelloCommand command)
{
return await _dispatcher.Send(command);
}
}This project is licensed under the Apache License.