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
                    
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="Decode.Extensions.Options" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Decode.Extensions.Options" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Decode.Extensions.Options" />
                    
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 Decode.Extensions.Options --version 3.0.0
                    
#r "nuget: Decode.Extensions.Options, 3.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.
#:package Decode.Extensions.Options@3.0.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=Decode.Extensions.Options&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Decode.Extensions.Options&version=3.0.0
                    
Install as a Cake Tool

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:

  1. the section must exist — verified immediately, at registration time;
  2. System.ComponentModel.DataAnnotations attributes on T must be satisfied;
  3. 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 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. 
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
3.0.0 95 9/14/2026
2.1.0 94 9/13/2026
2.0.2 90 9/13/2026
2.0.1 91 9/13/2026
2.0.0 128 7/28/2026
1.0.3 126 6/19/2026
1.0.2 125 5/26/2026
1.0.1 125 4/26/2026