Sondor.Options.FluentValidation 0.2.0

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

Sondor.Options.FluentValidation

FluentValidation for Sondor.Options. It validates options with the IValidator of their type when the host starts, and again each time the configuration reloads.

It is a separate package so that Sondor.Options has no third-party dependency. Use Validate, ValidateDataAnnotations or your own IValidateOptions instead and you do not need it.

dotnet add package Sondor.Options.FluentValidation
services.AddSondorOptions<DatabaseOptions>()
    .ValidateFluently<DatabaseOptions, DatabaseOptionsValidator>();     // registers the validator and validates with it

public sealed class DatabaseOptionsValidator : AbstractValidator<DatabaseOptions>
{
    public DatabaseOptionsValidator()
    {
        RuleFor(options => options.ConnectionString).NotEmpty();
        RuleFor(options => options.Timeout).InclusiveBetween(1, 300);
    }
}

If you register validators yourself (for example with AddValidatorsFromAssemblyContaining), use ValidateFluently() without the second type: it validates with whatever IValidator<DatabaseOptions> is in the container.

What you get

  • A failure reads as Validation failed for DatabaseOptions.Timeout with the error: ..., one for each failing rule, so the host's start-up error lists everything that is wrong at once.
  • Only the validator you ask for is registered. Nothing scans an assembly, so a validator you did not ask for never appears in the container (Sondor.Options 1.x registered every validator of the options' assembly).
  • Scoped dependencies work. Each validation resolves the validator from a scope of its own, which is disposed straight after.
  • With an optional section (SectionRequirement.Optional) that is not configured, the validator does not run: a feature that is off has nothing to validate. Once the section is there, it must be valid.
  • On a reload it behaves as the rest of Sondor.Options: an invalid change is rejected and the last valid options stay in use, unless you chose InvalidReloadBehavior.Fail.
  • Works on the framework's own builder too (services.AddOptions<T>().ValidateFluently()); validation then applies to the options of the name the builder was made for.

Limits

Only synchronous rules can be used. Options are built synchronously, so FluentValidation throws when it meets an asynchronous rule (MustAsync, CustomAsync), which fails the start. Keep option validation to the values themselves: a check that needs a network call does not belong in options validation.

If no IValidator<T> is in the container, the first validation fails with a message that says so.

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.  net11.0 is compatible. 
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.2.0 56 11/16/2026
0.1.0 57 11/13/2026
0.1.0-preview.1 55 11/13/2026