Decode.Extensions.Options
3.0.0
dotnet add package Decode.Extensions.Options --version 3.0.0
NuGet\Install-Package Decode.Extensions.Options -Version 3.0.0
<PackageReference Include="Decode.Extensions.Options" Version="3.0.0" />
<PackageVersion Include="Decode.Extensions.Options" Version="3.0.0" />
<PackageReference Include="Decode.Extensions.Options" />
paket add Decode.Extensions.Options --version 3.0.0
#r "nuget: Decode.Extensions.Options, 3.0.0"
#:package Decode.Extensions.Options@3.0.0
#addin nuget:?package=Decode.Extensions.Options&version=3.0.0
#tool nuget:?package=Decode.Extensions.Options&version=3.0.0
Decode.Extensions.Options
Utility extensions for the Options Pattern in .NET, ensuring that configurations are not only registered but also present and valid at runtime.
📦 Installation
dotnet add package Decode.Extensions.Options
🛠️ Usage
1. Registering Options with Mandatory Section
The AddValidatedOptions<T> method ensures that the section exists in your appsettings.json. By default, it looks for a section with the same name as the class T.
using Decode.Extensions.Options;
// In Program.cs
builder.Services.AddValidatedOptions<DatabaseSettings>(builder.Configuration);
Validation depth (changed in 2.0.0). Three checks now run, where previously only the first did:
- the section must exist — verified immediately, at registration time;
System.ComponentModel.DataAnnotationsattributes onTmust be satisfied;- that check runs at application start, not on first resolution.
Before 2.0.0 the method only confirmed the section existed and then called
Configure, despite its name. A section that was present but missing a[Required]property registered without complaint and failed later at runtime, far from the cause.
public class DatabaseSettings
{
[Required(ErrorMessage = "ConnectionString is required.")]
public string ConnectionString { get; set; } = string.Empty;
[Range(1, 300)]
public int CommandTimeoutSeconds { get; set; } = 30;
}
A missing ConnectionString now stops the host during startup with an OptionsValidationException
naming the offending property.
2. Immediate Configuration Access
Retrieve a configuration value directly from IConfiguration with immediate validation.
MySettings settings = builder.Configuration.GetValidatedSectionValue<MySettings>();
3. Benefit
Avoid "Silent Failures" where your application starts but crashes later because an IOptions<T> was injected with empty values due to a missing section in the configuration provider.
📄 License
MIT License.
| Product | Versions 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 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. |
-
net10.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Hosting (>= 8.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 8.0.0)
-
net8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Hosting (>= 8.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 8.0.0)
-
net9.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Hosting (>= 8.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.