Skip to content

Pragmatic.Configuration

Zero-boilerplate configuration binding, validation, and DI registration via source generator — plus runtime stores with cascade resolution, multi-tenancy, hot-reload, and pluggable backends.

Every IOptions<T> class needs the same binding/validation/registration boilerplate. Across 20 options classes that’s hundreds of lines of ceremony, and validation is opt-in: forget one .ValidateDataAnnotations() and [Required] is silently ignored until it fails at runtime.

// 4 lines of ceremony per options class, repeated for every config type
services.AddOptions<BookingOptions>()
.Bind(configuration.GetSection("Booking"))
.ValidateDataAnnotations()
.ValidateOnStart();

Beyond that: secrets vary by environment, dynamic reconfiguration needs a deploy, and per-tenant overrides become hardcoded switch statements.

Compile-time binding: annotate a class with [Configuration]; the generator produces the binding, DataAnnotation validation, and DI registration. One line registers everything.

[Configuration]
public partial class BookingOptions
{
[Required] public string CurrencyCode { get; init; } = "";
[Range(1, 365)] public int MaxStayDays { get; init; }
}

Runtime stores: a unified API over configuration with cascade resolution (global → tenant → user), hot-reload, and pluggable backends (Database, Azure) — without redeploying.

Terminal window
dotnet add package Pragmatic.Configuration
dotnet add package Pragmatic.SourceGenerator # generates the [Configuration] binding

[Configuration] binding/validation and the runtime stores (cascade, hot-reload, Database/Azure backends) are functional within the 0.8 preview. See the roadmap.

| Concepts | The two pillars, cascade resolution, hot-reload, choosing a backend | | Getting Started | Your first [Configuration] class and a runtime store | | Stores | Backends (Database, Azure), cascade, tenant overrides, hot-reload | | Common Mistakes | The most frequent configuration pitfalls | | Troubleshooting | Problem/solution guide with diagnostics |

  • .NET 10.0+
  • Pragmatic.SourceGenerator analyzer

Part of the Pragmatic.Design ecosystem — see Licensing. Pragmatic.Configuration is MIT-licensed.