C# Microsoft.NET edition
Welcome to the repository for the open source CAE CQRS Framework!
<ItemGroup>
<PackageReference Include="CleanArchEnablers.Utils.Cqrs" Version="${LatestVersion}">
</ItemGroup>
State Symbol Key:
✅
— Under release state✔️
— Under snapshot state⏳
— Under full development state
Commands are the part who will create, update or delete data in your database.
This is how we declare a Command:
public class YourCommand : ICommand { }
Queries are the part who will only read your database.
This is how we declare a Query:
public class YourCommand : IQuery { }
We need these type because we use in Dispatchers and Handlers.
We have 2 types of handlers, CommandHandler and QueryHandler.
The handlers are the implementation of our code, example:
public class CreateUserCommandHandler(IUserRepository repository)
: ICommandHandler<CreateUserCommand, CreateUserCommandResult>
{
private readonly IUserRepository _repository = repository;
public async Task<CreateUserCommandResult> Handle(CreateUserCommand command, CancellationToken cancellationToken)
{
var user = UserDomainEntityFactory.CreateInstance(command.Email, command.Password);
var result = await _repository.CreateUserAsync(user);
return new CreateUserCommandResult(result);
}
}
The dispatcher will be our bridge between the controllers and commands/queries. He will send a signal to run the implementations.
Example:
[ApiController]
[Route("/api/")]
public class UserController(IQueryDispatcher queryDispatcher)
: ControllerBase
{
[HttpGet("v1/user")]
public async Task<IActionResult> FetchUsers(CancellationToken cancellationToken)
{
var query = new FetchUsersQuery();
var users = await _queryDispatcher.Dispatch<FetchUsersQuery, FetchUsersQueryResult>(query, cancellationToken);
return Ok(users);
}
}
- To use
Cae.Cqrs
, you need to add on your IServiceCollection.
builder.Services.AddCaeCqrs(Assembly.GetExecutingAssembly());
CarCqrs
injects automatically any object implementingIQueryHandler<,>
orICommandHandler<,>
CAE — Clean Architecture made easy.