Vali-Validation.AspNetCore
1.1.0
dotnet add package Vali-Validation.AspNetCore --version 1.1.0
NuGet\Install-Package Vali-Validation.AspNetCore -Version 1.1.0
<PackageReference Include="Vali-Validation.AspNetCore" Version="1.1.0" />
<PackageVersion Include="Vali-Validation.AspNetCore" Version="1.1.0" />
<PackageReference Include="Vali-Validation.AspNetCore" />
paket add Vali-Validation.AspNetCore --version 1.1.0
#r "nuget: Vali-Validation.AspNetCore, 1.1.0"
#:package Vali-Validation.AspNetCore@1.1.0
#addin nuget:?package=Vali-Validation.AspNetCore&version=1.1.0
#tool nuget:?package=Vali-Validation.AspNetCore&version=1.1.0
Vali-Validation.AspNetCore
ASP.NET Core integration for Vali-Validation. Provides middleware, endpoint filters, and action filter attributes for automatic HTTP request validation.
- Targets: net7.0 / net8.0 / net9.0 / net10.0
- Depends on
Vali-Validation3.0.0+ — Severity-awareValidationResult, RuleSets, Localization,ValiValidationOptions.Global, andPropertyValidatorall work transparently through this package's middleware, filter, and attribute.
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."]
}
}
Severity note: the middleware, filter, and attribute all build this response from
ValidationResult.Errors, which only reflectsSeverity.Errorfailures. A rule marked.WithSeverity(Severity.Warning)(orSeverity.Info) never appears in the 400 response, even if it failed — read the full result viaIValidator<T>.ValidateAsyncyourself if you need to surface warnings to the client.
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 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. |
-
net10.0
- Vali-Validation (>= 3.0.0)
-
net7.0
- Vali-Validation (>= 3.0.0)
-
net8.0
- Vali-Validation (>= 3.0.0)
-
net9.0
- Vali-Validation (>= 3.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.
v1.1.0
- Adds net10.0 to the multi-targeted frameworks (now net7.0/net8.0/net9.0/net10.0).
- Now depends on Vali-Validation 3.0.0+, which brings Severity-aware ValidationResult,
RuleSets, block-level When/Unless, InjectValidator, Localization (English/Spanish built in),
ValiValidationOptions.Global, and PropertyValidator to any validator used through this
package's middleware/filter/attribute. No changes to this package's own public API.
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.