StrictConfig 1.0.1
dotnet add package StrictConfig --version 1.0.1
NuGet\Install-Package StrictConfig -Version 1.0.1
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="StrictConfig" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="StrictConfig" Version="1.0.1" />
<PackageReference Include="StrictConfig" />
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 StrictConfig --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: StrictConfig, 1.0.1"
#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 StrictConfig@1.0.1
#: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=StrictConfig&version=1.0.1
#tool nuget:?package=StrictConfig&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
StrictConfig
Strict configuration binding for .NET.
Use it when you want configuration errors to be obvious instead of permissive.
Why use it
StrictConfig is built to solve the parts of configuration binding that usually hurt in production:
- unknown keys being silently ignored
- invalid values surfacing too late
- nested validation being inconsistent
- reloads switching an app into a bad state
Quick start
using StrictConfig;
public sealed class AppSettings
{
public required string Name { get; set; }
public int Port { get; set; }
public DatabaseSettings Database { get; set; } = new();
}
public sealed class DatabaseSettings
{
public required string ConnectionString { get; set; }
}
AppSettings settings = configuration.GetSection("App").GetStrict<AppSettings>();
If binding fails, GetStrict<T>() throws a StrictBindException with all collected errors.
Non-throwing binding
if (!configuration.GetSection("App").TryBindStrict<AppSettings>(out var settings, out var errors))
{
foreach (var error in errors)
{
Console.WriteLine($"{error.Code} at {error.Path}: {error.Message}");
}
}
Existing-instance binding
var settings = new AppSettings { Name = "existing" };
configuration.GetSection("App").GetStrict(settings);
Split binding and validation options
var result = configuration.GetSection("App").BindStrict<AppSettings>(
binding => binding.ErrorOnUnknownKeys = false,
validation => validation.ValidateDataAnnotations = false);
DI and reload-aware options
builder.Services.AddStrictOptions<AppSettings>("App", builder.Configuration.GetSection("App"));
using var provider = builder.Services.BuildServiceProvider();
var monitor = provider.GetRequiredService<IStrictOptionsMonitor<AppSettings>>();
using var subscription = monitor.OnStrictReloadError("App", failure =>
Console.WriteLine($"{failure.Name} rejected: {failure.Errors[0].Code}"));
Strict reload behavior means:
- last known good values stay current
- invalid reloads are rejected
- failures are observable
Trimmed and NativeAOT apps
StrictConfig ships a built-in source generator.
using StrictConfig;
[StrictConfigSerializable(typeof(AppSettings))]
public partial class AppSettingsContext : StrictConfigContext
{
}
AppSettings settings = configuration
.GetSection("App")
.GetStrict<AppSettings>(AppSettingsContext.Default);
Use generated contexts when you need warning-clean trimmed or NativeAOT publishing.
What it supports
- scalars, enums, nullable values, arrays, lists, sets, and nested objects
- runtime-type binding
- constructor binding
- existing-instance updates
- immutable, concurrent, and read-only collections
- non-string-key dictionaries
DataAnnotations,IValidatableObject, and custom validators- custom converters and factories
- alias and ignore attributes
- exact
Code,Path,Message, andAttemptedValuediagnostics
Verification snapshot
75tests passing onnet8.075tests passing onnet10.0- about
74.92%line coverage - about
74.53%branch coverage - packaged consumer verification passes
- warning-clean trimmed publish verified
- warning-clean NativeAOT publish verified
| 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 was computed. 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.
-
net10.0
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.0)
-
net8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.0)
- System.Collections.Immutable (>= 10.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.