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
<PackageReference Include="LenzEng.Utilities.Cqrs.FluentValidation" Version="0.2.0" />
<PackageVersion Include="LenzEng.Utilities.Cqrs.FluentValidation" Version="0.2.0" />
<PackageReference Include="LenzEng.Utilities.Cqrs.FluentValidation" />
paket add LenzEng.Utilities.Cqrs.FluentValidation --version 0.2.0
#r "nuget: LenzEng.Utilities.Cqrs.FluentValidation, 0.2.0"
#:package LenzEng.Utilities.Cqrs.FluentValidation@0.2.0
#addin nuget:?package=LenzEng.Utilities.Cqrs.FluentValidation&version=0.2.0
#tool nuget:?package=LenzEng.Utilities.Cqrs.FluentValidation&version=0.2.0
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 | Versions 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. |
-
net10.0
- FluentValidation (>= 12.1.1)
- FluentValidation.DependencyInjectionExtensions (>= 12.1.1)
- LenzEng.Utilities.Cqrs (>= 0.2.0)
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 |