ReValidator.Validation.Mvc
1.0.0
dotnet add package ReValidator.Validation.Mvc --version 1.0.0
NuGet\Install-Package ReValidator.Validation.Mvc -Version 1.0.0
<PackageReference Include="ReValidator.Validation.Mvc" Version="1.0.0" />
<PackageVersion Include="ReValidator.Validation.Mvc" Version="1.0.0" />
<PackageReference Include="ReValidator.Validation.Mvc" />
paket add ReValidator.Validation.Mvc --version 1.0.0
#r "nuget: ReValidator.Validation.Mvc, 1.0.0"
#:package ReValidator.Validation.Mvc@1.0.0
#addin nuget:?package=ReValidator.Validation.Mvc&version=1.0.0
#tool nuget:?package=ReValidator.Validation.Mvc&version=1.0.0
ReValidator.Validation.Mvc
ReValidator.Validation.Mvc is a lightweight, generic validation adapter for ASP.NET Core MVC, built on top of the ReValidator engine. It allows you to apply strongly-typed, reusable validators to controller parameters using a simple [Validate] attribute, with full support for dependency injection and dynamic rules.
This package is fully compatible with .NET 6, 7, 8, 9, and works seamlessly alongside MVC.
Features
- Apply
[Validate]to any controller parameter. - Leverages your existing
IValidator<T>implementations. - Returns structured validation errors (RFC-7807 style).
- Supports dynamic rule injection at runtime.
- Optionally configure global MVC validation filter.
- Compatible with MVC for consistent behavior.
- Returns HTTP 422 Unprocessable Entity for failed validations.
Installation
Install via NuGet:
dotnet add package ReValidator.Validation.Mvc
Usage
- Add ReValidator services in
Program.cs
var builder = WebApplication.CreateBuilder(args);
// Add core ReValidator services
builder.Services.AddReValidator();
// Add MVC support
builder.Services.AddControllers();
builder.Services.AddReValidatorMvc();
// Optional: add global filter
// or add the mentioned filter per controller's action
builder.Services.AddControllers(options =>
{
options.Filters.Add<ReValidatorActionFilter>();
});
var app = builder.Build();
app.MapControllers();
app.Run();
- Create a validator
public sealed class PersonValidator : IValidator<Person>
{
public ValidationResult Validate(Person model)
{
var result = new ValidationResult();
if (string.IsNullOrWhiteSpace(model.Name))
result.Errors.Add(new ValidationError
{
Rule = "FullNameRequired",
Message = "The 'Name' property is required."
});
return result;
}
}
- Apply
[Validate]to controller parameters
[ApiController]
[Route("persons")]
public sealed class PersonsController : ControllerBase
{
[HttpPost("create")]
public IActionResult Create([Validate] Person person)
{
// This action will only execute
}
}
- Dynamic rule injection
app.Services.ApplyReconfiguration(new DynamicReconfiguration
{
RuleName = "FullNameRequired",
PropertyName = "Name",
ErrorMessage = "The \"{PropertyName}\" is required",
Expression = "x => !string.IsNullOrWhiteSpace(x.Name)",
FullPathToModel = typeof(Person).FullName
});
This allows you to inject or update rules at runtime, without recompiling validators.
- Validation response
When a validation fails, the API returns HTTP 422 with a structured payload:
{
"type": "about:blank",
"title": "Validation failed",
"status": 422,
"detail": "One or more validation rules were violated.",
"errors": [
{
"rule": "FullNameRequired",
"message": "The 'Name' property is required."
}
]
}
Unit Testing
You can use Microsoft.AspNetCore.TestHost to test MVC endpoints:
using var app = await CreateApplication();
var client = app.GetTestClient();
var response = await client.PostAsJsonAsync("/persons/create", new Person());
Assert.Equal(422, (int)response.StatusCode);
Requirements
- NET 6.0 or higher
- ReValidator.Contracts
- ASP.NET Core MVC (Abstractions + Core)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. 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. |
-
net6.0
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.3.9)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.9)
- ReValidator.Contracts (>= 1.0.1)
-
net7.0
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.3.9)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.9)
- ReValidator.Contracts (>= 1.0.1)
-
net8.0
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.3.9)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.9)
- ReValidator.Contracts (>= 1.0.1)
-
net9.0
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.3.9)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.9)
- ReValidator.Contracts (>= 1.0.1)
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 |
|---|---|---|
| 1.0.0 | 100 | 1/12/2026 |