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" />
<PackageReference Include="Sondor.AspNetCore.FluentValidation" />
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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
#tool nuget:?package=Sondor.AspNetCore.FluentValidation&version=0.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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 ownValidateAndThrowAsync, orSondor.Cqrs.FluentValidationfor a request whose response type has no failure factory. - A failed
Resultfrom a request thatSondor.Cqrs.FluentValidation0.2.1 or later refused andSondor.Cqrs.Results0.2.1 or later answered. Its error keeps the messages of each property as aDataargument namedErrors, and the response gets the sameerrorsmember. AResultwhose 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].UnitPricebecomesitems[0].unitPrice); the indexer is kept. With the policy set tonullthe 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 codeSondor.Cqrs.FluentValidationuses. The status is the one ofErrorType.ValidationinErrorResponseOptions.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
WithMessagewhere that matters. - Your own mapping wins. The package maps
ValidationExceptionthroughErrorResponseOptions.Exceptions; a mapping you add afterwards replaces it, and theerrorsmember is still added. - Calling it twice is harmless. Nothing is registered a second time.
| 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. net11.0 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- FluentValidation (>= 12.2.0)
- Sondor.AspNetCore (>= 0.2.0)
- Sondor.Results (>= 0.3.0)
-
net11.0
- FluentValidation (>= 12.2.0)
- Sondor.AspNetCore (>= 0.2.0)
- Sondor.Results (>= 0.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.