Options.FluentValidations
1.0.0
.NET 7.0
This package targets .NET 7.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
dotnet add package Options.FluentValidations --version 1.0.0
NuGet\Install-Package Options.FluentValidations -Version 1.0.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="Options.FluentValidations" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Options.FluentValidations --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Options.FluentValidations, 1.0.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.
// Install Options.FluentValidations as a Cake Addin #addin nuget:?package=Options.FluentValidations&version=1.0.0 // Install Options.FluentValidations as a Cake Tool #tool nuget:?package=Options.FluentValidations&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Introduction
Options.FluentValidation adds extension methods on top of Microsoft.Extensions.Options to be able to use FluentValidation for validating your options.
services.AddOptions<TestOption>()
.Bind(config.GetSection("Options"))
.ValidateFluently();
How to use
Start by creation your option record:
namespace Options;
public record AppOptions
{
public const string SectionName = "App";
public string Name { get; init; }
public int WorkerCount { get; init; }
}
Create an FluentValidation class:
using FluentValidation;
namespace Options;
public class AppOptionsValidation : AbstractValidator<AppOptions>
{
public AppOptionsValidation()
{
RuleFor(o => o.Name)
.NotEmpty()
.NotNull();
RuleFor(o => o.WorkerCount)
.GreaterThan(0)
.LessThan(20);
}
}
Then add the option to your IServiceCollection
by following:
using Options.FluentValidation;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace Options;
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddOptions(this IServiceCollection services, IConfiguration config)
{
services.AddOptions<AppOptions>()
.Bind(config.GetRequiredSection(AppOptions.SectionName))
.ValidateFluently()
.ValidateOnStart(); // Add Microsoft.Extensions.Hosting package
return services;
}
}
Then you can add the configuration to your json
file or any other means of setting up your configurations.
{
"App": {
"Name": "My fancy app",
"WorkerCount": 15
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.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.
-
.NETStandard 2.0
- FluentValidation (>= 11.5.1)
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
- Microsoft.Extensions.Options (>= 7.0.1)
-
net7.0
- FluentValidation (>= 11.5.1)
- Microsoft.Extensions.DependencyInjection (>= 7.0.0)
- Microsoft.Extensions.Options (>= 7.0.1)
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 | 209 | 4/7/2023 |
1.0.0-preview | 120 | 4/7/2023 |