ForEvolve.FluentValidation.AspNetCore.Http
1.0.25
See the version list below for details.
dotnet add package ForEvolve.FluentValidation.AspNetCore.Http --version 1.0.25
NuGet\Install-Package ForEvolve.FluentValidation.AspNetCore.Http -Version 1.0.25
<PackageReference Include="ForEvolve.FluentValidation.AspNetCore.Http" Version="1.0.25" />
paket add ForEvolve.FluentValidation.AspNetCore.Http --version 1.0.25
#r "nuget: ForEvolve.FluentValidation.AspNetCore.Http, 1.0.25"
// Install ForEvolve.FluentValidation.AspNetCore.Http as a Cake Addin #addin nuget:?package=ForEvolve.FluentValidation.AspNetCore.Http&version=1.0.25 // Install ForEvolve.FluentValidation.AspNetCore.Http as a Cake Tool #tool nuget:?package=ForEvolve.FluentValidation.AspNetCore.Http&version=1.0.25
FluentValidation.AspNetCore.Http
A simple ASP.NET Core 7+ Minimal API integration for FluentValidation 10+.
The package leverages endpoint filters to trigger FluentValidation IValidator<T>
. In case of a validation error, the filter returns a TypedResults.ValidationProblem(errors);
, where the errors
argument represents the collection of failures. You can customize this behavior by implementing the IFluentValidationEndpointFilterResultsFactory
interface.
How to install
dotnet add package ForEvolve.FluentValidation.AspNetCore.Http
Pre-release feedz.io URL:
https://f.feedz.io/forevolve/fluentvalidation/nuget/index.json
How to use
In your Program.cs
file, you must register the library:
builder.AddFluentValidationEndpointFilter();
You can then add the validation filter to an endpoint:
using FluentValidation.AspNetCore.Http;
//...
app.MapGet("/some-path", (SomeParamToValidate model) => {
// ...
}).AddFluentValidationFilter();
You can also add the validation filter to a group instead, which applies the filter to all of the group's endpoints:
using FluentValidation.AspNetCore.Http;
//...
var root = app
.MapGroup("/")
.AddFluentValidationFilter()
;
// Then you can register endpoints that will get validated, like:
root.MapGet("/some-path", (SomeParamToValidate model) => {
//...
});
You must register your validators normally. Here is an example that has nothing to do with this library and only uses FluentValidation:
// Using the assembly scanning feature
builder.Services.AddValidatorsFromAssemblyContaining<Program>();
// Manually registering a validator
builder.Services.AddScoped<IValidator<MyEntity>, MyEntityValidator>();
Settings
You can configure the FluentValidationEndpointFilterSettings
class during the registration as follow:
builder.AddFluentValidationEndpointFilter(settings => {
settings.ScanningStrategy = ScanningStrategy.ScanUntilNoValidatorFound;
});
You can also leverage ASP.NET Core Configure
and PostConfigure
methods as usual, like this:
builder.Services.Configure<FluentValidationEndpointFilterSettings>(options =>
{
options.ScanningStrategy = ScanningStrategy.ScanUntilNoValidatorFound;
});
Finally, you can configure the filter in the appsettings.json
file under the FluentValidationEndpointFilter
key, like this:
{
"FluentValidationEndpointFilter": {
"ScanningStrategy": "ScanUntilNoValidatorFound"
}
}
ScanningStrategy
The only configuration at this time is the scanning strategy that contains the following options:
ScanAllParams
(default behavior): The filter scans all parameters. For each parameter, it tries to get anIValidator<T>
instance from the ASP.NET Core container. When it finds one, the filter validates the parameter.ScanUntilNoValidatorFound
: The filter scans parameters until it does not find a validator for a parameter. When that happens, the validation stops.When using this strategy, you must first add the objects to validate, then add the services or other injected types.
Examples
You can browse the examples
directory for usage examples.
Versioning
The package follows semantic versioning and uses Nerdbank.GitVersioning under the hood to automate versioning based on Git commits.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- FluentValidation (>= 10.0.0)
-
net8.0
- FluentValidation (>= 10.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.