Kopticx.Validify 2.1.0

dotnet add package Kopticx.Validify --version 2.1.0
                    
NuGet\Install-Package Kopticx.Validify -Version 2.1.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="Kopticx.Validify" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kopticx.Validify" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Kopticx.Validify" />
                    
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 Kopticx.Validify --version 2.1.0
                    
#r "nuget: Kopticx.Validify, 2.1.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 Kopticx.Validify@2.1.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=Kopticx.Validify&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Kopticx.Validify&version=2.1.0
                    
Install as a Cake Tool

Kopticx.Validify

NuGet .NET

Validify is a lightweight validation filter for ASP.NET Core Minimal APIs powered by FluentValidation. It wires model validation into your endpoint pipeline with one line per endpoint — and a source generator registers all your validators for you, with zero runtime reflection so the whole thing stays fully Native AOT compatible.


✨ Features

  • ✅ Declarative model validation for Minimal APIs via .WithValidation<T>()
  • 🔄 Built on FluentValidation — full rule set: conditional, cross-property, async, custom messages
  • 🤖 Source-generated auto-registration — one AddValidifyValidators() call registers every validator; no manual AddSingleton per model
  • 📦 Per-project registration — auto-registers the validators of the project it's installed in; register cross-assembly validators manually with AddSingleton
  • ⚙️ 100% Native AOT compatible — discovery happens at compile time, no runtime reflection
  • 🛡️ Stops invalid requests before they reach your handlers, with an RFC 9457 HttpValidationProblemDetails
  • 🧩 Plug-and-play with Microsoft.Extensions.DependencyInjection

🚀 Installation

dotnet add package Kopticx.Validify

🛠️ Setup

1. Register Validify

builder.Services.AddValidify();            // the validation filter
builder.Services.AddValidifyValidators();  // source-generated — registers all your validators

2. Write FluentValidation validators

public sealed class PostUserModelValidator : AbstractValidator<PostUserModel>
{
    public PostUserModelValidator()
    {
        RuleFor(x => x.Username)
            .NotEmpty().WithMessage("Username is required")
            .MaximumLength(255).WithMessage("Must be less than 255 characters");
    }
}

3. Apply validation to an endpoint

app.MapPost("/users", PostUser)
   .WithValidation<PostUserModel>();

If the model is invalid, the filter short-circuits with a 400 Bad Request carrying an HttpValidationProblemDetails (RFC 9457) — your handler never runs.


🤖 Auto-registration (source generator)

AddValidifyValidators() is generated at compile time into your startup assembly. It discovers every AbstractValidator<T> and registers IValidator<T> → your concrete validator — no reflection, no per-model boilerplate.

It registers with TryAdd, so it coexists with manual registration: anything you register by hand takes precedence, and the generator fills in the rest.

// Still valid — a manual registration wins over the generated one:
services.AddSingleton<IValidator<PostUserModel>, PostUserModelValidator>();

Discovery is per-project: the generator registers validators declared in the project where the package is installed. To register a validator that lives in another assembly, register it by hand (it coexists with the generated registrations):

services.AddSingleton<IValidator<SomeModel>, SomeValidator>();

The default lifetime is Scoped (matching FluentValidation's own default); override it if needed:

builder.Services.AddValidifyValidators(ServiceLifetime.Singleton);

⚙️ Native AOT

Validify is 100% AOT-compatible: discovery and registration are resolved at compile time with no runtime reflection. Publish your API as a native executable:

<PublishAot>true</PublishAot>

So the 400 response can be serialized under source-generated System.Text.Json, add HttpValidationProblemDetails to your JsonSerializerContext:

[JsonSerializable(typeof(HttpValidationProblemDetails))]
public partial class AppJsonContext : JsonSerializerContext;

The repo's samples/Validify.AotSample is a Minimal API published with PublishAot that registers its validators through the generator — proving the AOT path end to end.


🤔 Validify vs .NET 10 native validation

.NET 10 introduced built-in Minimal API validation (AddValidation() plus a source generator over DataAnnotations attributes) — a great fit when DataAnnotations covers your needs. Validify is for teams who prefer FluentValidation:

Validify .NET 10 native validation
Validation engine FluentValidation DataAnnotations
Where rules live Dedicated validator classes, decoupled from the model Attributes on the model
Expressiveness Fluent API: conditional, cross-property, async, custom messages Attribute set; custom via IValidatableObject / custom attributes
Validator testability Plain classes, unit-testable in isolation Coupled to the model
Registration One source-generated AddValidifyValidators() (or manual) AddValidation() + source-gen over annotated types
Discovery scope The installing project's validators (cross-assembly is manual) Per annotated type
Native AOT
Minimum target .NET 8 .NET 10

Both are source-generated and AOT-friendly — the real decision is FluentValidation vs DataAnnotations.


📝 License

License: MIT


📄 Third-party licenses

Validify uses FluentValidation, licensed under the Apache 2.0 License.

See NOTICE file for more information.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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. 
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
2.1.0 108 6/20/2026
2.0.0 104 6/19/2026
1.0.0 212 7/2/2025