Validonce.AspNetCore 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Validonce.AspNetCore --version 0.2.0
                    
NuGet\Install-Package Validonce.AspNetCore -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="Validonce.AspNetCore" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Validonce.AspNetCore" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Validonce.AspNetCore" />
                    
Project file
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 Validonce.AspNetCore --version 0.2.0
                    
#r "nuget: Validonce.AspNetCore, 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 Validonce.AspNetCore@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=Validonce.AspNetCore&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Validonce.AspNetCore&version=0.2.0
                    
Install as a Cake Tool

Validonce.AspNetCore

Cross-field validation for ASP.NET Core, written once in FluentValidation. Requests that break a rule get an RFC 7807 response with status 422. The same rules are published in your OpenAPI document as x-validonce, so clients can evaluate them too.

Install

dotnet add package Validonce.AspNetCore

It brings Validonce.FluentValidation and Validonce, and needs the ASP.NET Core shared framework (net10.0).

Example

using Validonce;
using Validonce.AspNetCore;
using Validonce.FluentValidation;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddValidonce();                                    // singleton IValidator<T> for every ValidonceValidator<T>
builder.Services.AddOpenApi(o => o.AddValidonceSchemaTransformer()); // adds x-validonce to schemas

var app = builder.Build();
app.MapOpenApi();
app.MapPost("/signups", (Signup s) => Results.Ok()).WithValidonce(); // endpoint filter
app.Run();

public sealed record Signup(string? Plan, string? Company, DateOnly? Start, DateOnly? End);

public sealed class SignupValidator : ValidonceValidator<Signup>
{
    public SignupValidator()
    {
        RequiredWhen(x => x.Company, If.Eq(x => x.Plan, "pro")).WithMessageKey("rules.company_required");
        Compare(x => x.End, CompareOp.Ge, x => x.Start).WithMessageKey("rules.end_after_start");
    }
}

Controllers (MVC)

builder.Services.AddValidonce();
builder.Services.AddControllers();
builder.Services.AddValidonceMvc();   // validates action arguments, same response

The 422 body

{
  "title": "One or more validation errors occurred.",
  "status": 422,
  "errors": { "Company": ["rules.company_required"] },
  "validonce": [
    { "path": ["company"], "ruleId": "Signup.required_when.company",
      "key": "rules.company_required", "params": {} }
  ]
}

validonce is the same issue list the client evaluators produce. Set options.ValidationStatusCode in AddValidonce(o => o.ValidationStatusCode = 400) to change the status.

The rule format is described at https://github.com/metatoy/validonce/blob/main/docs/rule-format-v1.md. Source and issues: https://github.com/metatoy/validonce.

Copyright 2026 Metatoy LLC. Licensed under the Apache License, Version 2.0.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.6.0 70 11/30/2026
0.5.0 97 11/25/2026
0.4.0 96 11/24/2026
0.3.3 97 11/24/2026
0.3.1 95 11/24/2026
0.3.0 93 11/24/2026
0.2.0 93 11/23/2026