i26.Cqrs 0.5.0

dotnet add package i26.Cqrs --version 0.5.0
                    
NuGet\Install-Package i26.Cqrs -Version 0.5.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="i26.Cqrs" Version="0.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="i26.Cqrs" Version="0.5.0" />
                    
Directory.Packages.props
<PackageReference Include="i26.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 i26.Cqrs --version 0.5.0
                    
#r "nuget: i26.Cqrs, 0.5.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 i26.Cqrs@0.5.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=i26.Cqrs&version=0.5.0
                    
Install as a Cake Addin
#tool nuget:?package=i26.Cqrs&version=0.5.0
                    
Install as a Cake Tool

i26.Cqrs

Commands, queries and their handlers, with no mediator in the middle. A caller asks the container for the handler of the exact request it means, which the compiler checks and a reader can follow to its declaration.

dotnet add package i26.Cqrs

Commands and queries

A request is a record, its handler is a class, and the handler answers with a Result. There is no mediator in the middle: a caller asks the container for the handler of the exact request it means, which the compiler checks and a reader can follow to its declaration.

using i26.Cqrs;

public sealed record PublishCourseCommand(CourseId Id) : ICommand;              // no response
public sealed record CreateCourseCommand(string Title) : ICommand<CourseId>;    // with one
public sealed record GetCourseQuery(CourseId Id) : IQuery<CourseResponse>;      // reads only

internal sealed class PublishCourseHandler(ICourseRepository courses)
    : ICommandHandler<PublishCourseCommand>
{
    public async Task<Result> HandleAsync(PublishCourseCommand command, CancellationToken ct = default)
    {
        var course = await courses.FindAsync(command.Id, ct);

        if (course is null)
        {
            return CourseErrors.NotFound;
        }

        return course.Publish();
    }
}

The response type lives on the request, so ICommandHandler<CreateCourseCommand, CourseId> and every call site agree on it without anyone restating it.

Registration

The library cannot see your handlers, so you call this from wherever the application layer wires itself up:

using i26.Cqrs;

public static class DependencyInjection
{
    public static IServiceCollection AddApplication(this IServiceCollection services)
    {
        services.AddHandlers(typeof(DependencyInjection).Assembly);
        // validators, decorators, services…

        return services;
    }
}

Every handler in the assembly is registered scoped, under the interfaces it implements — internal and private ones included, since a handler is an implementation detail of the application layer and has no reason to be public. Endpoints then ask for one directly:

[FromServices] ICommandHandler<PublishCourseCommand> handler

Two handlers for one request is refused, naming both, instead of resolving to whichever was scanned last. That is the failure mode of copying a handler and forgetting to change the request it handles, and it is silent everywhere else. Scanning the same assembly twice is harmless.

Decorators

Nothing here is decorated for you — validation, logging, transactions and caching are decisions about your application, not about a library. The registration is the plain closed-generic kind, so Scrutor wraps it the usual way:

services.Decorate(typeof(ICommandHandler<,>), typeof(ValidationDecorator.CommandHandler<,>));
services.Decorate(typeof(ICommandHandler<>), typeof(LoggingDecorator.CommandBaseHandler<>));

Domain events

AddDomainEvents() registers the queue and a dispatcher that runs the handlers in process, in the scope that published. The handlers themselves come from AddHandlers above, and the events themselves are i26.Core.

services.AddHandlers(typeof(DependencyInjection).Assembly);
services.AddDomainEvents();

Collecting them as entities are saved is i26.EntityFrameworkCore; handling them off the request is i26.Hosting.

A dispatcher of your own

AddDomainEvents registers one that runs the handlers in process, in the scope that published, and registers it only if nothing else claimed IDomainEventDispatcher. Handing the events to a background queue instead is a class:

internal sealed class BackgroundDomainEventsDispatcher(IBackgroundJobScheduler scheduler)
    : IDomainEventDispatcher
{
    public Task DispatchAsync(IReadOnlyList<IDomainEvent> domainEvents, CancellationToken ct = default)
    {
        foreach (var domainEvent in domainEvents)
        {
            scheduler.Enqueue<ProcessDomainEventJob>(domainEvent, ct);
        }

        return Task.CompletedTask;
    }
}
services.AddScoped<IDomainEventDispatcher, BackgroundDomainEventsDispatcher>();
services.AddDomainEvents();

What it drags in

Microsoft.Extensions.DependencyInjection.Abstractions, and i26.Core.


Part of i26.

Product Compatible and additional computed target framework versions.
.NET 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.  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 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 (1)

Showing the top 1 NuGet packages that depend on i26.Cqrs:

Package Downloads
i26.Hosting

Background handling of i26 domain events: a dispatcher that queues them in memory and a hosted service that runs the handlers off the request, each in a scope of its own.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.0 183 8/13/2026
0.4.0 151 8/13/2026
0.3.1 153 8/13/2026
0.3.0 142 8/12/2026
0.2.0 143 8/12/2026
0.1.0 148 8/12/2026