Sondor.Cqrs.FluentValidation 0.3.0

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

Sondor.Cqrs.FluentValidation

FluentValidation for Sondor.Cqrs. It runs every validator of a request before its handler, so a request is validated the same way whatever sent it (HTTP, a message, background work), and an invalid request never reaches the handler.

It is a separate package so that Sondor.Cqrs itself has no third-party dependency. If you move to another validation library, remove this package and write a behaviour for it; nothing else changes.

dotnet add package Sondor.Cqrs.FluentValidation
services.AddValidatorsFromAssemblyContaining<RegisterNodeValidator>();   // FluentValidation.DependencyInjectionExtensions
services.AddCqrs(cqrs =>
{
    cqrs.AddHandlersFromAssemblyContaining<RegisterNodeHandler>();
    cqrs.UseTracing();
    cqrs.UseFluentValidation();        // after what should see refused requests, before the handler
});

public sealed class RegisterNodeValidator : AbstractValidator<RegisterNode>
{
    public RegisterNodeValidator() => RuleFor(command => command.Name).NotEmpty().WithMessage("A name is required.");
}

The package does not register your validators. Register them yourself, for example with AddValidatorsFromAssemblyContaining from FluentValidation.DependencyInjectionExtensions. Every IValidator<TRequest> found in the container runs, one after another.

What happens to an invalid request

It depends on whether the response type can say "refused":

Response type An invalid request
Has an IFailureFactory<TResponse> registered Returns the failure it builds, with the code Validation.Failed (CqrsValidation.ErrorCode), kind Validation, and the validators' messages, each once, joined with a space.
Has none Throws FluentValidation's ValidationException, which carries every failure.

With Sondor.Cqrs.Results and services.AddCqrsResults(), a request that returns Result or Result<T> gets a failed result with an error of type Validation. For another response type, register your own factory:

public sealed class ReplyFailureFactory : IFailureFactory<Reply>
{
    public Reply Create(RequestFailure failure) => new(false, failure.Code, failure.Description);
}

Things that behave in a specific way

  • The messages are your validators' messages. FluentValidation's default messages for some rules include the rejected value (for example "You entered 15"). If a message can reach a client, write your own with WithMessage, or leave the value out of it. The package adds nothing from the request.
  • The failure carries the messages of each property. A failure factory also receives RequestFailure.Errors (property name, as the validator reported it, to its messages, each once), so a response can keep the breakdown that the joined description loses. It needs Sondor.Cqrs 0.2.1 or later.
  • A span is tagged, never the values. When the request is traced, cqrs.validation.properties lists the names of the properties that were refused and cqrs.validation.error_count how many failures there were.
  • A request with no validator costs nothing. It goes straight on.
  • Validators run asynchronously. ValidateAsync is used, so async rules (MustAsync, CustomAsync) work, and the request's cancellation token reaches them.
  • Where you put UseFluentValidation() matters. Behaviours run in the order added, the first one outermost. Put things that should see every attempt, such as auditing, before it.
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.  net11.0 is compatible. 
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 83 11/16/2026
0.2.1 100 11/14/2026
0.2.0 56 11/13/2026
0.1.0 57 11/13/2026