FluentAnnotationsValidator 1.2.2

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

FluentAnnotationsValidator

A fluent, type-safe validation engine for .NET that transforms [ValidationAttribute] annotations into runtime validation logic. Supports conditional rules, culture-scoped messages, and discoverable configuration via DSL.


Features

  • Automatic validation from [Required], [Range], [EmailAddress], etc.
  • Culture-aware localization from .resx or static resource classes
  • Conditional logic per property via .When(...), .Localized(...), .UseFallbackMessage(...)
  • Implicit rule generation based on global config (.WithCulture(...), .WithValidationResource(...))
  • Smooth integration with ASP.NET and IValidator<T>
  • DSL configuration: target types, cultures, resource mapping, conventions

Quick Setup

Fluent Validation Configuration

Start with automatic rule generation via [ValidationAttribute], then layer culture and localization resources:

using FluentAnnotationsValidator.Extensions;
using System.Globalization;

services.AddFluentAnnotationsValidators(typeof(LoginDto))
    .UseFluentAnnotations()
    .For<LoginDto>()
        .WithCulture(CultureInfo.GetCultureInfo("fr-FR"))
        .WithValidationResource<ValidationMessages>() // Scoped .resx lookup
    .Build();

Or inject conditional validation logic with localized error fallback:

services.UseFluentAnnotations()
    .For<LoginDto>()
        .WithCulture(CultureInfo.GetCultureInfo("fr-FR"))
        .WithValidationResource<ValidationMessages>()
        .When(x => x.Password, dto => string.IsNullOrEmpty(dto.Password))
            .Localized("Password_Required") // Looks up ValidationMessages.Password_Required
            .UseFallbackMessage("Mot de passe requis.") // Fallback if resource key is missing
    .Build();

⚠️ Heads-up: Current version supports only one rule per property.
If a property has multiple [ValidationAttribute]s, only the last one will be processed.
This will be resolved in v2.0.0 with full multi-attribute resolution.


v1.2.2 Highlights

  • Fixed implicit rule synthesis for attributes lacking .When(...)
  • Respects global culture and resource bindings during fallback
  • Improved configurator registry architecture for future rule aggregation
  • Warning added for multi-attribute scenarios pending v2.0.0 release

Installation

dotnet add package FluentAnnotationsValidator --version 1.2.2

Test Coverage

  • [Required], [EmailAddress], [MinLength], [Range] support
  • ✅ Localized message binding from culture+resource
  • ✅ Fallback behavior for .Build() without manual rule definitions

Learn More


Highlights

  • WithCulture(...) binds CultureInfo globally across rules for this type.
  • WithValidationResource<T>() uses .resx-backed messages with safe fallback.
  • When(...) applies targeted conditions with fluent chaining for per-property logic.
  • Localized(...) uses string keys like "Email_Required", typically mapped to ValidationMessages resource entries.

Documentation

See configuration guide for advanced usage.

Contribute

Open to feedback, extensions, and collaboration - shape validation ergonomics for developers worldwide.

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 365 7/25/2025
1.2.2 489 7/23/2025
1.2.1 490 7/22/2025
1.2.0 479 7/22/2025
1.1.0 435 7/21/2025