Vali-Validation.AspNetCore
1.0.3
dotnet add package Vali-Validation.AspNetCore --version 1.0.3
NuGet\Install-Package Vali-Validation.AspNetCore -Version 1.0.3
<PackageReference Include="Vali-Validation.AspNetCore" Version="1.0.3" />
<PackageVersion Include="Vali-Validation.AspNetCore" Version="1.0.3" />
<PackageReference Include="Vali-Validation.AspNetCore" />
paket add Vali-Validation.AspNetCore --version 1.0.3
#r "nuget: Vali-Validation.AspNetCore, 1.0.3"
#:package Vali-Validation.AspNetCore@1.0.3
#addin nuget:?package=Vali-Validation.AspNetCore&version=1.0.3
#tool nuget:?package=Vali-Validation.AspNetCore&version=1.0.3
Vali-Validation.AspNetCore
ASP.NET Core integration for Vali-Validation. Provides middleware, endpoint filters, and action filter attributes for automatic HTTP request validation.
Installation
dotnet add package Vali-Validation.AspNetCore
Features
- ValiValidationMiddleware — catches
ValidationExceptionand returns an RFC 7807problem+jsonHTTP 400 response. - ValiValidationFilter<T> — Minimal API
IEndpointFilterthat validates a request DTO before the endpoint executes. - ValiValidateAttribute — MVC
IAsyncActionFilterattribute for automatic controller action validation.
ValiValidationMiddleware
Catches any ValidationException thrown anywhere in the pipeline and returns a structured 400 response.
// Program.cs
app.UseValiValidationExceptionHandler(); // place before routing/controllers
Optional DI helper for ProblemDetails:
builder.Services.AddValiValidationProblemDetails();
ValiValidationFilter<T> — Minimal API
Validates a bound argument of type T before the endpoint executes. If no IValidator<T> is registered, the filter is a no-op.
// Using the fluent extension (recommended)
app.MapPost("/users", (CreateUserDto dto) => Results.Ok())
.WithValiValidation<CreateUserDto>();
// Or explicitly
app.MapPost("/users", (CreateUserDto dto) => Results.Ok())
.AddEndpointFilter<ValiValidationFilter<CreateUserDto>>();
Validators must be registered in DI:
builder.Services.AddScoped<IValidator<CreateUserDto>, CreateUserDtoValidator>();
// or using the bulk-registration helper from Vali-Validation:
builder.Services.AddValidationsFromAssembly(typeof(CreateUserDtoValidator).Assembly);
ValiValidateAttribute — MVC Controllers
Apply to a controller or a single action to validate all incoming arguments automatically.
[ApiController]
[ValiValidate]
public class UsersController : ControllerBase
{
[HttpPost]
public IActionResult Create(CreateUserDto dto) => Ok();
}
Or per action:
[HttpPost]
[ValiValidate]
public IActionResult Create(CreateUserDto dto) => Ok();
Validation Error Response Format (RFC 7807)
When validation fails, the response is HTTP 400 with Content-Type: application/problem+json:
{
"type": "https://tools.ietf.org/html/rfc7807",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"Name": ["'Name' must not be empty."],
"Email": ["'Email' is not a valid email address."],
"Age": ["'Age' must be greater than 0."]
}
}
Donations
If Vali-Validation is useful to you, consider supporting its development:
- Latin America — MercadoPago
- International — PayPal
License
Contributions
Issues and pull requests are welcome on GitHub.
| 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net7.0
- Vali-Validation (>= 2.0.2)
-
net8.0
- Vali-Validation (>= 2.0.2)
-
net9.0
- Vali-Validation (>= 2.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.0.0 — Initial release.
- ValiValidationMiddleware catches ValidationException, returns RFC 7807 problem+json.
- ValiValidationFilter<T> (IEndpointFilter) for Minimal API endpoint validation.
- ValiValidateAttribute (IAsyncActionFilter) for MVC controller action validation.
- UseValiValidationExceptionHandler() middleware registration.
- WithValiValidation<T>() fluent extension for Minimal API routes.
- AddValiValidationProblemDetails() DI helper.