Neoxack.CQRS
1.1.5
See the version list below for details.
dotnet add package Neoxack.CQRS --version 1.1.5
NuGet\Install-Package Neoxack.CQRS -Version 1.1.5
<PackageReference Include="Neoxack.CQRS" Version="1.1.5" />
paket add Neoxack.CQRS --version 1.1.5
#r "nuget: Neoxack.CQRS, 1.1.5"
// Install Neoxack.CQRS as a Cake Addin
#addin nuget:?package=Neoxack.CQRS&version=1.1.5
// Install Neoxack.CQRS as a Cake Tool
#tool nuget:?package=Neoxack.CQRS&version=1.1.5
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 scopedIQueryDispatcher
as scopedICommandHandler<,>
concrete implementations as scopedIQueryHandler<,>
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 | Versions 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 was computed. 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. |
-
net6.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.