LenzEng.Utilities.Cqrs.FluentValidation 0.2.0

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

LenzEng.Utilities.Cqrs.FluentValidation

FluentValidation integration for LenzEng.Utilities.Cqrs. Adds automatic command validation before dispatch, without changing the core library.

What It Provides

Type Purpose
ValidatingCommandProcessor ICommandProcessor decorator that runs a command's IValidator<TCommand> (if one is registered) before calling the real handler
ValidateCommandException Thrown when validation fails; carries the ValidationFailure list
AddCqrsValidation(...) DI extension that registers validators found in the given assembly/assemblies and wraps ICommandProcessor with the validating decorator

How It Works

AddCqrsValidation replaces the ICommandProcessor registration made by the core library's AddCqrs with a decorator: it resolves IValidator<TCommand> for the command being processed, runs it if present, and only calls through to the original processor if validation passes (or if no validator is registered for that command type — validation is opt-in per command). This requires no changes to CommandProcessor itself, keeping the core project free of any FluentValidation dependency.

AddCqrs(...) must be called before AddCqrsValidation(...) — the decorator wraps whatever ICommandProcessor is already registered.

Quick Start

// 1. Define a command and a validator for it
public class CreateOrderCommand : ICommand
{
    public string ProductId { get; set; } = string.Empty;
    public int Quantity { get; set; }
}

public class CreateOrderCommandValidator : AbstractValidator<CreateOrderCommand>
{
    public CreateOrderCommandValidator()
    {
        RuleFor(c => c.ProductId).NotEmpty();
        RuleFor(c => c.Quantity).GreaterThan(0);
    }
}

// 2. Register — AddCqrs first, then AddCqrsValidation
services.AddCqrs(typeof(CreateOrderCommandHandler).Assembly);
services.AddCqrsValidation(typeof(CreateOrderCommandValidator).Assembly);

// 3. Dispatch as usual — validation runs automatically
try
{
    var result = await commandProcessor.ProcessAsync(new CreateOrderCommand { Quantity = 0 }, ct);
}
catch (ValidateCommandException ex)
{
    // ex.CommandType, ex.Errors (IReadOnlyCollection<FluentValidation.Results.ValidationFailure>)
    // Map to a 400 Bad Request or similar in your own exception handling — this library
    // stays HTTP-agnostic, same as the core project.
}

Technical Documentation

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

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.2.0 43 7/3/2026