Skip to content

clean-arch-enablers-project/CleanArchEnablers.Utils.Cqrs

Repository files navigation

✔️ CleanArchEnablers.Utils.Cqrs

C# Microsoft.NET edition


Welcome to the repository for the open source CAE CQRS Framework!

▶️ The NuGet Package:

<ItemGroup>
    <PackageReference Include="CleanArchEnablers.Utils.Cqrs" Version="${LatestVersion}">
</ItemGroup>

State Symbol Key:

  • Under release state
  • ✔️Under snapshot state
  • Under full development state



📚 Key Concepts

Command - Queries

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.

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);
    }
}

Dispatchers

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);
    }
}

⚠️ Attention

  • To use Cae.Cqrs, you need to add on your IServiceCollection.
builder.Services.AddCaeCqrs(Assembly.GetExecutingAssembly());
  • CarCqrs injects automatically any object implementing IQueryHandler<,> or ICommandHandler<,>

🌐 Other components of the SDK:




CAE — Clean Architecture made easy.

About

CaeCqrs Implementation for .NET

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages