LenzEng.Utilities.Cqrs.Rest 0.3.0

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

LenzEng.Utilities.Cqrs.Rest

ASP.NET Core integration for LenzEng.Utilities.Cqrs. Converts the raw results your command/query handlers return into IActionResult, so controllers never construct HTTP responses by hand.

What It Provides

Type Purpose
AddCqrsRest() Registers IControllerCommandProcessor/IControllerQueryProcessor
IControllerCommandProcessor / IControllerQueryProcessor Resolve and invoke the registered REST handler for a command/query, returning IActionResult directly
AddCreatedAtRouteControllerCommand<TCommand, TResult>(...) Registers a command whose handler creates a resource → 201 Created with a Location header
AddCNoContentControllerCommand<TCommand>() Registers a command → 204 No Content
AddControllerQuery<TQuery>(...) Registers a query → 200 OK
ControllerCommandHandlerBase<T> / ControllerQueryHandlerBase<T> Base classes for hand-written handlers the generic ones don't cover — expose Ok/NoContent/NotFound/BadRequest/CreatedAtRoute helpers

Key Behaviour

  • 404 Not Found happens automatically when a handler returns LenzEng.Utilities.Cqrs.NotFoundMarker instead of a result — no exception needed.
  • 400 Bad Request happens automatically if LenzEng.Utilities.Cqrs.FluentValidation's ValidateCommandException is thrown, with the validation errors in the response body — this package doesn't reference that one, it just catches the exception type by name from the core package.
  • Conversion functions are typed as Func<object, object> rather than Func<TDomain, TDto> on purpose, so the generic handlers stay decoupled from your domain/DTO types — the cast happens inside the converter you supply.

Quick Start

// 1. Register the core CQRS processors (from LenzEng.Utilities.Cqrs) and this package's
builder.Services.AddCqrs(typeof(CreateOrderCommandHandler).Assembly);
builder.Services.AddCqrsRest();

// 2. Configure each command/query
builder.Services.AddCreatedAtRouteControllerCommand<CreateOrderCommand, Order>(opts =>
{
    opts.RouteName = "GetOrderById";
    opts.IdProperty = o => o.Id;
});
builder.Services.AddCNoContentControllerCommand<CancelOrderCommand>();
builder.Services.AddControllerQuery<GetOrderByIdQuery>();

// 3. Controllers just dispatch — no manual IActionResult construction
public class OrdersController : ControllerBase
{
    private readonly IControllerCommandProcessor _commands;
    private readonly IControllerQueryProcessor _queries;

    public OrdersController(IControllerCommandProcessor commands, IControllerQueryProcessor queries)
    {
        _commands = commands;
        _queries = queries;
    }

    [HttpPost]
    public Task<IActionResult> Create(CreateOrderCommand command, CancellationToken ct)
        => _commands.ProcessAsync(command, ct);

    [HttpGet("{id:guid}", Name = "GetOrderById")]
    public Task<IActionResult> GetById(Guid id, CancellationToken ct)
        => _queries.ProcessAsync(new GetOrderByIdQuery { OrderId = id }, ct);
}

Technical Documentation

Full reference and worked examples: src/LenzEng.Utilities.Cqrs.Rest — GitLab

See the Packages Work Together

The sample project's README is the best place to go next: a small, runnable movie-catalog API built on all three packages — LenzEng.Utilities.Cqrs, this one, and LenzEng.Utilities.Cqrs.FluentValidation — together. It's a genuinely good, step-by-step guide to how the three fit together in practice: how a request flows through every layer, what each line of DI registration actually does, and two worked recipes for adding a new endpoint from scratch. Written to be followable even if you're fairly new to the pattern.

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.3.0 38 7/12/2026