Neoxack.CQRS 1.2.0

dotnet add package Neoxack.CQRS --version 1.2.0
NuGet\Install-Package Neoxack.CQRS -Version 1.2.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="Neoxack.CQRS" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Neoxack.CQRS --version 1.2.0
#r "nuget: Neoxack.CQRS, 1.2.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.
// Install Neoxack.CQRS as a Cake Addin
#addin nuget:?package=Neoxack.CQRS&version=1.2.0

// Install Neoxack.CQRS as a Cake Tool
#tool nuget:?package=Neoxack.CQRS&version=1.2.0

.NET NuGet NuGet

CQRS

This library provides a .NET implementation of the CQRS pattern, allowing you to separate command and query responsibilities in your applications. CQRS promotes a clear separation between the command side that performs operations and the query side that retrieves data.

Installing CQRS

You should install Neoxack.CQRS with NuGet:

Install-Package Neoxack.CQRS

Or via the .NET Core command line interface:

dotnet add package Neoxack.CQRS

Either commands, from Package Manager Console or .NET Core CLI, will download and install Neoxack.CQRS and all required dependencies.

Example

public class PingCommand : ICommand<string>
{
    public string Value { get; }

    public PingCommand(string value)
    {
        Value = value;
    }
}
public class PingCommandHandler : ICommandHandler<PingCommand, string>
{
    public string Handle(PingCommand command)
    {
        return command.Value;
    }
}
public class PingController
{
    private readonly IQueryDispatcher _queryDispatcher;
    private readonly ICommandDispatcher _commandDispatcher;

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

    [HttpPost("ping")]
    public string Ping()
    {
        return _commandDispatcher.Execute(new PingCommand("Ping"));
    }
}

Registering with IServiceCollection

CQRS supports Microsoft.Extensions.DependencyInjection.Abstractions directly. To register CQRS services and handlers:

services.AddCQRS(typeof(Startup).Assembly);

This registers:

  • ICommandDispather as scoped
  • IQueryDispatcher as scoped
  • ICommandHandler<,> concrete implementations as scoped
  • IQueryHandler<,> concrete implementations as scoped

Benchmarks

BenchmarkDotNet v0.13.10, macOS Sonoma 14.1.2 (23B92) [Darwin 23.1.0]
Apple M2 Pro, 1 CPU, 12 logical and 12 physical cores
.NET SDK 8.0.100
  [Host]     : .NET 6.0.20 (6.0.2023.32017), Arm64 RyuJIT AdvSIMD
  DefaultJob : .NET 6.0.20 (6.0.2023.32017), Arm64 RyuJIT AdvSIMD
Method Mean Error StdDev Ratio RatioSD Gen0 Allocated Alloc Ratio
Neoxack.CQRS 73.89 ns 0.167 ns 0.140 ns 1.00 0.00 0.0114 24 B 1.00
MediatR 189.76 ns 2.430 ns 2.154 ns 2.57 0.02 0.1760 368 B 15.33

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.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.2.0 82 5/25/2024
1.1.5 312 2/12/2024
1.1.4 261 12/10/2023
1.1.3 103 12/10/2023
1.1.2 87 12/10/2023
1.1.1 138 11/19/2023
1.1.0 107 11/12/2023
1.0.1 567 12/5/2022
1.0.0 154 12/5/2022