FluentAnnotationsValidator 2.0.0-preview1

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

FluentAnnotationsValidator

A fluent, type-safe validation engine for .NET that transforms [ValidationAttribute] annotations into runtime validation logic. Designed for ergonomic configuration, conditional logic, and culture-aware localization.


🌟 What's New in v2.0.0-preview1

FluentAnnotationsValidator v2.0.0-preview1 is a fresh rewrite. All legacy APIs from v1.x have been removed.

  • Multi-attribute validation per property
  • DSL-based configuration via ValidationConfigurator
  • Conditional rules with .When(...), .Localized(...), .UseFallbackMessage(...)
  • Convention-based registration from scanned assemblies
  • Pluggable IValidationMessageResolver
  • Scoped culture + resource binding per type
  • Legacy support removed — clean slate architecture

To use the legacy version, pin to v1.2.2.


Quickstart

Basic Setup

Using AddFluentAnnotations():

using FluentAnnotationsValidator.Extensions;

services.AddFluentAnnotations();

Advanced Setup

Using either:

  1. AddFluentAnnotationsValidators(...):
services.AddFluentAnnotationsValidators(typeof(LoginDto))
    .UseFluentAnnotations()
    .For<LoginDto>()
        .WithCulture(CultureInfo.GetCultureInfo("fr-FR"))
        .WithValidationResource<ValidationMessages>()
    .Build();
  1. AddFluentAnnotations(...) with common behavior options configuration:
services.AddFluentAnnotations(
    configureBehavior: options =>
    {
        // common culture and resource type for all validation attributes
        options.CommonCulture = CultureInfo.GetCultureInfo("fr-FR");
        options.CommonResourceType = typeof(ValidationMessages);
    }
);
  1. AddFluentAnnotations(...) with scoped and common culture and resource types:
services.AddFluentAnnotations(
    builder =>
        // Conditional Localization rule for German 
        // culture and resource type scoped to LoginDto
        builder.For<LoginDto>()
            .When(x => x.LangCode == 'DE')
            .WithCulture(CultureInfo.GetCultureInfo("de-DE"))
            .WithValidationResource<AuthenticationMessages>()
        .Build(),
    configureBehavior: options =>
    {
        // common French culture and resource type for all validation rules
        options.CommonCulture = CultureInfo.GetCultureInfo("fr-FR");
        options.CommonResourceType = typeof(ValidationMessages);
    }
);

Installation

dotnet add package FluentAnnotationsValidator --version 2.0.0-preview1

Key Concepts

Concept Description
ValidationBehaviorOptions Registry of validation rules discovered via scanning or configuration
FluentAnnotationsBuilder Configuration anchor: links DI services + options
ValidationConfigurator Fluent DSL to configure conditional logic, culture, and resource resolution
IValidationMessageResolver Pluggable fallback resolution for localized messages
DataAnnotationsValidator<T> Runtime validator that hydrates validation rules from metadata and rules registry

Test Coverage

  • [Required], [EmailAddress], [MinLength], [Range], [StringLength]
  • .resx and static resource support
  • ✅ Record constructor annotations
  • ✅ Upfront rule hydration + conditional overrides

Learn More


Contribute

Help shape validation ergonomics for developers worldwide. Open to extensions, diagnostics, and new DSL patterns — bring your ideas!

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.0.0-preview1 397 7/25/2025
2.0.0-preview.2.2 97 8/31/2025
1.2.2 547 7/23/2025
1.2.1 518 7/22/2025
1.2.0 533 7/22/2025
1.1.0 477 7/21/2025