Ling.FluentValidation 1.0.0-preview.2

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

Ling.FluentValidation

Project documentation | 简体中文

Ling.FluentValidation provides the source generator, FluentValidation rule extensions, and compatible runtime validators. The generator is shipped as a compiler-only asset, while DTO declarations live in the dependency-free Ling.FluentValidation.Annotations package.

Installation

Install the package in the application or validation project that should own generated validators:

<PackageReference Include="Ling.FluentValidation" Version="..." />

The package references Ling.FluentValidation.Annotations transitively, including its analyzer and code-fix assets. Contract projects should nevertheless reference Ling.FluentValidation.Annotations directly and should not reference this runtime package.

Generate from a contract assembly

using Ling.FluentValidation.Annotations;
using MyApplication.Contracts;

[assembly: GenerateValidatorsFromAssemblyContaining(typeof(CreateOrderRequest))]
[assembly: ValidatorGenerationOptions(
    Namespace = "MyApplication.Validation",
    Visibility = GeneratedValidatorVisibility.Public)]

Only explicitly selected referenced assemblies are examined. Marked DTOs in the current assembly are generated automatically.

Extend a generated validator

Generated validators are partial and expose a parameterless constructor plus ConfigureAdditionalRules:

using FluentValidation;
using MyApplication.Contracts;

namespace MyApplication.Validation;

public sealed partial class CreateOrderRequestValidator
{
    partial void ConfigureAdditionalRules()
    {
        RuleFor(request => request.Name)
            .Must(name => !name.StartsWith("test-"))
            .WithMessage("Reserved order name.");
    }
}

For rules with dependencies, add a constructor that chains to the generated constructor:

public CreateOrderRequestValidator(IOrderPolicy policy) : this()
{
    RuleFor(request => request.Name)
        .MustAsync(policy.IsAllowedAsync);
}

Register generated validators

Every receiving assembly gets a GeneratedValidatorRegistry containing target-to-validator mappings. When DI abstractions are referenced, a conventional extension method is generated too:

var services = new ServiceCollection();
services.AddGeneratedValidators();

Registration uses generated concrete types and does not scan assemblies.

Other assemblies can retrieve the generated validator types directly:

IReadOnlyList<Type> validatorTypes =
    GeneratedValidatorRegistry.ValidatorTypes;

IReadOnlyDictionary<Type, Type> validatorsByTargetType =
    GeneratedValidatorRegistry.ValidatorTypesByTargetType;

The returned collection is read-only and stable for the generated assembly.

Localization

The first Ling rule extension adds Ling messages directly to the current manager when it derives from FluentValidation.Resources.LanguageManager. It never replaces the manager or changes its settings:

ValidatorOptions.Global.LanguageManager.Culture = new CultureInfo("zh-CN");

Custom ILanguageManager implementations can import every entry from LingValidatorTranslations.All; a one-time Trace warning is emitted when automatic registration is unavailable.

Supported frameworks

Runtime assets are provided for:

  • .NET Standard 2.0 and 2.1
  • .NET Core 3.1
  • .NET 5 through .NET 10

The package uses a tested FluentValidation major-version range for each target framework.

  • Ling.FluentValidation.Annotations contains dependency-free declarations, analyzers, and code fixes.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  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 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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
1.0.0-preview.2 74 8/31/2026
1.0.0-preview.1 63 8/31/2026