Sondor.AspNetCore.FluentValidation 0.2.0

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

Sondor.AspNetCore.FluentValidation

FluentValidation for Sondor.AspNetCore. When a ValidationException leaves a request, the problem response is a 400 with the usual errorCode and traceId and an errors member that lists the messages of each property.

It is a separate package so that Sondor.AspNetCore itself has no third-party dependency.

dotnet add package Sondor.AspNetCore.FluentValidation
builder.Services.AddSondorProblemDetails();
builder.Services.AddSondorFluentValidationProblems();

app.UseSondorProblemDetails();
{
  "status": 400,
  "title": "Bad Request",
  "detail": "One or more validation errors occurred.",
  "errorCode": "Validation.Failed",
  "traceId": "00-...",
  "errors": {
    "name": ["A name is required."],
    "address.postCode": ["The post code is not valid."],
    "items[0].unitPrice": ["The price must be positive."]
  }
}

Where the failure comes from

  • A ValidationException: your own ValidateAndThrowAsync, or Sondor.Cqrs.FluentValidation for a request whose response type has no failure factory.
  • A failed Result from a request that Sondor.Cqrs.FluentValidation 0.2.1 or later refused and Sondor.Cqrs.Results 0.2.1 or later answered. Its error keeps the messages of each property as a Data argument named Errors, and the response gets the same errors member. A Result whose error has no such argument (Error.Invalid(...), or an error you built) gets none.

Things that behave in a specific way

  • Property names follow the API's JSON naming policy (ConfigureHttpJsonOptions, camelCase by default), so they match the properties of the request body. Each name in a path is converted (Items[0].UnitPrice becomes items[0].unitPrice); the indexer is kept. With the policy set to null the names are left as FluentValidation reports them.
  • Several messages for one property are listed in the order they were reported, each once. A failure with no property name is listed under the empty name "".
  • The code is Validation.Failed (FluentValidationProblemsExtensions.ErrorCode), the same code Sondor.Cqrs.FluentValidation uses. The status is the one of ErrorType.Validation in ErrorResponseOptions.StatusByType (400 by default); set it to 422 if you prefer.
  • The messages are your validators' messages, sent to the caller as they are. FluentValidation's default message for some rules includes the rejected value, so write your own with WithMessage where that matters.
  • Your own mapping wins. The package maps ValidationException through ErrorResponseOptions.Exceptions; a mapping you add afterwards replaces it, and the errors member is still added.
  • Calling it twice is harmless. Nothing is registered a second time.
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.2.0 64 11/16/2026
0.1.0 69 11/14/2026