ITB.CQRS 2.1.0

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

ITB.CQRS

CQRS, Repository and Specification building blocks for .NET 10 applications on Entity Framework Core.

Package Namespace What it contains
ITB.CQRS ITB.CQRS Commands, queries, handlers, IHandlerDispatcher, decorators, filtered/paged list queries
ITB.Repository.Abstraction ITB.Repository.Abstraction IReadRepository<T>, IRepository<T>
ITB.Repository.EntityFrameworkCore ITB.Repository.EntityFrameworkCore EF Core repositories and IUnitOfWork
ITB.Specification ITB.Specification Specification pattern with &, |, ! composition and includes
ITB.ResultModel ITB.Shared.Result Result, Result<T> and the Failure hierarchy
ITB.Shared.Domain ITB.Domain.Entities, ITB.Domain.Interfaces IEntity, Entity<TKey>, IQueryableFilter<T>

Getting started

dotnet add package ITB.CQRS
dotnet add package ITB.Repository.EntityFrameworkCore
builder.Services.AddDbContext<AppDbContext>(...);
// Repositories and the transaction decorator resolve the base DbContext type.
builder.Services.AddScoped<DbContext>(sp => sp.GetRequiredService<AppDbContext>());

builder.Services.AddRepositories();
builder.Services.AddQueryableFilters(typeof(Program).Assembly);
builder.Services.AddSpecificationFactory();
builder.Services.AddCQRS([typeof(Program).Assembly]);

AddCQRS scans the given assemblies for handlers, FluentValidation validators, IPermissionValidator<T>, IAccessFilter<T> and Mapster configurations.

Commands and queries

public class CreateClient : CommandBase<int>
{
    public string Name { get; set; }
}

public class CreateClientHandler(IRepository<Client> clients, IUnitOfWork unitOfWork)
    : CommandHandlerBase<CreateClient, int>
{
    public override async Task<Result<int>> Handle(CreateClient input)
    {
        var client = await clients.Add(new Client(input.Name));
        await unitOfWork.SaveChanges();
        return client.Id;
    }
}

// Controller / endpoint
var result = await dispatcher.Handle<CreateClient, int>(command);

Every handler is wrapped by decorators, outermost first:

  1. ErrorHandlerDecorator turns an unhandled exception into an ExceptionFailure (configurable through CQRSOptions.ExceptionHandler).
  2. PermissionValidationHandlerDecorator runs every IPermissionValidator<TIn> and returns ForbiddenFailure on failure.
  3. ValidationHandlerDecorator runs every FluentValidation IValidator<TIn> and returns ValidationFailure.
  4. TransactionHandlerDecorator wraps commands (CommandBase) in a database transaction inside the EF execution strategy and commits only on success. Mark a command with [IgnoreTransaction] to opt out.

Filtered lists

Derive the query from GetFilteredListQuery<TOut> and the handler from GetFilteredListQueryHandler<TIn, TOut, TEntity>. Override CheckAccess, BuildSpecification, BuildBaseQuery, Search, Sort or GetItems as needed; the result is projected to TOut with Mapster and returned as PagedList<TOut> with the total count.

Helpers:

  • FilterValidationExtensions.MustBeValidSortPath(...) rejects unknown sort columns in a validator.
  • LikePatterns.Contains(value) escapes %, _ and \ for EF.Functions.Like(..., LikePatterns.EscapeChar).

Migrating from 1.x

2.0 is a breaking release:

  • Target framework is net10.0.
  • SimpleInjector was replaced by Microsoft.Extensions.DependencyInjection (with Scrutor). AddCQRS no longer takes a Container.
  • AutoMapper was replaced by Mapster. GetFilteredListQueryHandler no longer takes an IMapper.
  • Handler contracts dropped the Task<Result<...>> wrapper from the generic argument: ICommand<TOut> / IHandler<TIn, TOut> now return Task<Result<TOut>>, and result-less commands use ICommand / IHandler<TIn>. HandlerBase was removed.
  • SortOrder is now an enum; Sorting.Path no longer parses .Asc / .Desc suffixes.
  • PagedList<T>.Count is int (always populated) instead of int?.
  • ApplyPageFilter now defaults to 10 000 items when no page size is given, and clamps negative sizes and overflowing offsets.
  • AddRepositories() returns IServiceCollection; RepositoryBuilder was removed and AddQueryableFilters is an extension on IServiceCollection.
  • Namespaces: ITB.ResultModel → ITB.Shared.Result, ITB.Shared.Domain → ITB.Domain.Entities / ITB.Domain.Interfaces.
  • The previously separate repositories (ITB.Repository, ITB.Specification, ITB.Shared) now live here.

Releasing

Packages are published by pushing a version tag:

git tag v2.0.0 && git push origin v2.0.0

A tag with a prerelease suffix (v2.0.0-beta.1) publishes prerelease packages.

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
2.1.0 139 9/25/2026
2.0.1 95 9/23/2026
2.0.0 100 9/23/2026
1.8.0 16,920 3/29/2024
1.6.1 18,278 9/20/2022
1.6.0 5,011 6/28/2022
1.0.5 4,599 10/8/2020
1.0.4 1,447 9/25/2020
1.0.3 1,003 5/18/2020
1.0.2 641 5/7/2020
1.0.1 668 5/4/2020
1.0.0 688 4/30/2020