Fluens.Cqrs 0.7.7

There is a newer version of this package available.
See the version list below for details.
dotnet add package Fluens.Cqrs --version 0.7.7
                    
NuGet\Install-Package Fluens.Cqrs -Version 0.7.7
                    
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="Fluens.Cqrs" Version="0.7.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fluens.Cqrs" Version="0.7.7" />
                    
Directory.Packages.props
<PackageReference Include="Fluens.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 Fluens.Cqrs --version 0.7.7
                    
#r "nuget: Fluens.Cqrs, 0.7.7"
                    
#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 Fluens.Cqrs@0.7.7
                    
#: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=Fluens.Cqrs&version=0.7.7
                    
Install as a Cake Addin
#tool nuget:?package=Fluens.Cqrs&version=0.7.7
                    
Install as a Cake Tool

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
PageIndex pi 1
PageSize ps 20
SortOrder so null
SortProperty sp null

PageIndex and PageSize are clamped on assignment via PagingDefaults.ClampPageIndex / ClampPageSize: null passes through unclamped (meaning "not specified"), PageIndex is floored at DefaultPageIndex (the index 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 (DefaultPageIndex, 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).

License

This project is licensed under the MIT License.

Product 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. 
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
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
Loading failed