Fluens.Cqrs
0.9.3
See the version list below for details.
dotnet add package Fluens.Cqrs --version 0.9.3
NuGet\Install-Package Fluens.Cqrs -Version 0.9.3
<PackageReference Include="Fluens.Cqrs" Version="0.9.3" />
<PackageVersion Include="Fluens.Cqrs" Version="0.9.3" />
<PackageReference Include="Fluens.Cqrs" />
paket add Fluens.Cqrs --version 0.9.3
#r "nuget: Fluens.Cqrs, 0.9.3"
#:package Fluens.Cqrs@0.9.3
#addin nuget:?package=Fluens.Cqrs&version=0.9.3
#tool nuget:?package=Fluens.Cqrs&version=0.9.3
Fluens.Cqrs
CQRS pattern implementation with command/query dispatchers, handler interfaces, and logging/tracing decorators.
Installation
dotnet add package Fluens.Cqrs
Usage
Registration
fluensBuilder
.AddCqrs()
.AddCqrsHandlers<Program>()
.AddCqrsLoggingDecorator()
.AddCqrsTracingDecorator();
AddCqrsLoggingDecorator() and AddCqrsTracingDecorator() may be called in any order relative to
AddCqrsHandlers<T>() / AddHandlers() — the decorator request is parked and applied to every current
and future matching handler registration, and calling either decorator method (or AddCqrs()) more than
once never double-wraps a handler. The tracing decorator emits spans on the Fluens.Cqrs
ActivitySource (owned statically by the library, never injected via DI); subscribe to it by listing
"Fluens.Cqrs" in ObservabilityOptions.AdditionalSources.
Commands
// Command without return value
public record CreateOrder(string Number) : ICommand;
public class CreateOrderHandler : ICommandHandler<CreateOrder>
{
public async Task<Result> HandleAsync(CreateOrder command, CancellationToken cancellationToken)
{
// ...
return Result.Success();
}
}
// Command with return value
public record GetOrder(int Id) : ICommand<OrderDto>;
public class GetOrderHandler : ICommandHandler<GetOrder, OrderDto>
{
public async Task<Result<OrderDto>> HandleAsync(GetOrder command, CancellationToken cancellationToken)
{
// ...
return Result.Success(new OrderDto());
}
}
Paginated Queries
public class SearchOrders : PagedQuery<PagedResult<OrderDto>>
{
public string? Term { get; set; }
}
PagedQuery<TResult> is an abstract class (not a record — a record cannot derive from a plain
abstract class) that provides default pagination properties with [JsonPropertyName] short codes to
minimize JSON payload:
| Property | Short code | Default |
|---|---|---|
Page |
p |
1 |
PageSize |
ps |
20 |
SortOrder |
so |
null |
SortProperty |
sp |
null |
Page and PageSize are clamped on assignment via PagingDefaults.ClampPage /
ClampPageSize: null passes through unclamped (meaning "not specified"), Page is floored at
DefaultPage (the page number is 1-based), and PageSize is clamped between MinPageSize and
MaxPageSize. Subclasses automatically inherit the short names in any JsonSerializerContext - no extra
configuration required. Pagination constants are available via Constants.Cqrs.Query
(DefaultPage, DefaultPageSize, MinPageSize, MaxPageSize).
Queries
public record ListOrders(string? Term) : IQuery<IReadOnlyList<OrderDto>>;
public class ListOrdersHandler : IQueryHandler<ListOrders, IReadOnlyList<OrderDto>>
{
public async Task<IReadOnlyList<OrderDto>> HandleAsync(ListOrders query, CancellationToken cancellationToken)
{
// Queries return the result directly (no Result wrapper)
return [];
}
}
Module-Level Registration
// In IModuleSetup.RegisterServices:
module.AddHandlers(); // scans module assembly, validates assembly boundaries
AddHandlers() scans the module assembly for handler implementations, registers them with scoped lifetime, and enforces module boundary rules: handlers can only handle commands/queries defined in the same module assembly, and cross-module dispatch at runtime throws InvalidOperationException. The runtime guard runs on all three ICommandDispatcher.SendAsync overloads (including the strongly-typed SendAsync<TCommand, TResult>) as well as IQueryDispatcher.SendAsync — none of the dispatch surfaces can bypass module-boundary enforcement.
Dispatching
// Inject ICommandDispatcher / IQueryDispatcher
Result result = await commandDispatcher.SendAsync(new CreateOrder("ORD-001"), ct);
IReadOnlyList<OrderDto> orders = await queryDispatcher.SendAsync(new ListOrders("test"), ct);
Built-in decorators: LoggingCommandHandlerDecorator (logs execution), TracingCommandHandlerDecorator
(OpenTelemetry activity on the Fluens.Cqrs source — sets ActivityStatusCode.Ok on success and
ActivityStatusCode.Error both when the inner handler throws and when it returns a failed Result).
When the handler throws while its CancellationToken is cancelled (e.g. the client aborted the HTTP
request and SqlClient threw SqlException), the span gets a cancelled event instead and its status
stays unset - a caller cancellation is not a failure. The exception is always rethrown.
License
This project is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Fluens (>= 0.9.3)
- Fluens.Kernel (>= 0.9.3)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.13)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.13)
- Scrutor (>= 7.0.0)
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 |
|---|---|---|
| 0.9.4 | 252 | 11/30/2026 |
| 0.9.3 | 281 | 11/17/2026 |
| 0.9.2 | 131 | 10/21/2026 |
| 0.9.1 | 471 | 10/13/2026 |
| 0.9.0 | 108 | 10/13/2026 |
| 0.8.7 | 261 | 10/12/2026 |
| 0.8.6 | 120 | 10/12/2026 |
| 0.8.5 | 118 | 10/7/2026 |
| 0.8.4 | 106 | 10/6/2026 |
| 0.8.3 | 109 | 10/6/2026 |
| 0.8.2 | 179 | 10/5/2026 |
| 0.8.1 | 154 | 9/15/2026 |
| 0.8.0 | 117 | 9/15/2026 |
| 0.7.11 | 122 | 9/15/2026 |
| 0.7.10 | 126 | 9/13/2026 |
| 0.7.9 | 125 | 9/11/2026 |
| 0.7.8 | 134 | 9/10/2026 |
| 0.7.7 | 143 | 9/10/2026 |
| 0.7.6 | 185 | 7/1/2026 |
| 0.7.5 | 148 | 6/22/2026 |