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
<PackageReference Include="Sondor.Options.FluentValidation" Version="0.2.0" />
<PackageVersion Include="Sondor.Options.FluentValidation" Version="0.2.0" />
<PackageReference Include="Sondor.Options.FluentValidation" />
paket add Sondor.Options.FluentValidation --version 0.2.0
#r "nuget: Sondor.Options.FluentValidation, 0.2.0"
#:package Sondor.Options.FluentValidation@0.2.0
#addin nuget:?package=Sondor.Options.FluentValidation&version=0.2.0
#tool nuget:?package=Sondor.Options.FluentValidation&version=0.2.0
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 choseInvalidReloadBehavior.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 | Versions 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. |
-
net10.0
- FluentValidation (>= 12.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Options (>= 10.0.15)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.15)
- Sondor.Options (>= 2.1.0)
-
net11.0
- FluentValidation (>= 12.2.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 11.0.0)
- Sondor.Options (>= 2.1.0)
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 |