Devsquare.CQRS 1.0.0

dotnet add package Devsquare.CQRS --version 1.0.0
                    
NuGet\Install-Package Devsquare.CQRS -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Devsquare.CQRS" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Devsquare.CQRS" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Devsquare.CQRS" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Devsquare.CQRS --version 1.0.0
                    
#r "nuget: Devsquare.CQRS, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Devsquare.CQRS@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Devsquare.CQRS&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Devsquare.CQRS&version=1.0.0
                    
Install as a Cake Tool

Devsquare.EasyCQRS

A lightweight CQRS (Command Query Responsibility Segregation) implementation for .NET 9 applications, built on Clean Architecture principles and using MediatR for command and query dispatching.

Features

  • Clean separation of commands and queries following CQRS pattern
  • Comprehensive dependency injection support
  • Seamless integration with ASP.NET Core
  • Minimal external dependencies
  • Type-safe command and query dispatching

Installation

dotnet add package Devsquare.EasyCQRS

Usage

Setting Up Dependency Injection

// In Program.cs or Startup.cs
using Devsquare.EasyCQRS.Implementations;

var builder = WebApplication.CreateBuilder(args);

// Add EasyCQRS services with automatic handler registration
// Pass the assemblies containing your command and query handlers
builder.Services.AddEasyCQRS(typeof(Program).Assembly);

Defining Commands and Queries

// Command example
public class CreateUserCommand : ICommand<Guid>
{
    public string Username { get; set; }
    public string Email { get; set; }
}

// Command handler
public class CreateUserCommandHandler : ICommandHandler<CreateUserCommand, Guid>
{
    public async Task<Guid> HandleAsync(CreateUserCommand command, CancellationToken cancellationToken)
    {
        // Implementation logic
        var userId = Guid.NewGuid();
        return userId;
    }
}

// Query example
public class GetUserByIdQuery : IQuery<UserDto>
{
    public Guid UserId { get; set; }
}

// Query handler
public class GetUserByIdQueryHandler : IQueryHandler<GetUserByIdQuery, UserDto>
{
    public async Task<UserDto> HandleAsync(GetUserByIdQuery query, CancellationToken cancellationToken)
    {
        // Implementation logic
        return new UserDto { /* ... */ };
    }
}

Using the Command and Query Dispatchers

// In a controller or service
public class UserController : ControllerBase
{
    private readonly ICommandDispatcher _commandDispatcher;
    private readonly IQueryDispatcher _queryDispatcher;

    public UserController(ICommandDispatcher commandDispatcher, IQueryDispatcher queryDispatcher)
    {
        _commandDispatcher = commandDispatcher;
        _queryDispatcher = queryDispatcher;
    }

    [HttpPost]
    public async Task<IActionResult> CreateUser(CreateUserCommand command)
    {
        var userId = await _commandDispatcher.SendAsync(command);
        return Ok(userId);
    }

    [HttpGet("{id}")]
    public async Task<IActionResult> GetUser(Guid id)
    {
        var query = new GetUserByIdQuery { UserId = id };
        var user = await _queryDispatcher.SendAsync(query);
        return Ok(user);
    }
}
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 263 4/13/2025