Raycynix.Extensions.Configuration
2.2.0
dotnet add package Raycynix.Extensions.Configuration --version 2.2.0
NuGet\Install-Package Raycynix.Extensions.Configuration -Version 2.2.0
<PackageReference Include="Raycynix.Extensions.Configuration" Version="2.2.0" />
<PackageVersion Include="Raycynix.Extensions.Configuration" Version="2.2.0" />
<PackageReference Include="Raycynix.Extensions.Configuration" />
paket add Raycynix.Extensions.Configuration --version 2.2.0
#r "nuget: Raycynix.Extensions.Configuration, 2.2.0"
#:package Raycynix.Extensions.Configuration@2.2.0
#addin nuget:?package=Raycynix.Extensions.Configuration&version=2.2.0
#tool nuget:?package=Raycynix.Extensions.Configuration&version=2.2.0
Raycynix.Extensions.Configuration
Raycynix.Extensions.Configuration contains the core typed-configuration registration helpers for Raycynix applications.
What it contains
AddRaycynixEnvironment()AddRaycynixEnvironment(string)AddRaycynixConfigurationSources(...)UseRaycynixConfigurationSources(...)AddRaycynixFeatureFlags(...)AddRaycynixConfiguration<TOptions>(...)ConfigureRaycynixConfigurationDiagnostics(...)AddRaycynixConfigurationRedactor<TRedactor>()AddRaycynixConfigurationRedactor(...)AddRaycynixConfigurationAccessor<TOptions>()AddRaycynixConfigurationValidator<TOptions, TValidator>()AddRaycynixConfigurationValidator<TOptions>(...)AddRaycynixConfigurationReloadPolicy<TOptions, TReloadPolicy>()AddRaycynixConfigurationReloadPolicy<TOptions>(...)AddRaycynixConfigurationChangeHandler<TOptions, THandler>()AddRaycynixConfigurationChangeHandler<TOptions>(...)- typed configuration binding based on the standard Options pipeline
- standard environment abstraction based on
IHostEnvironment - standard configuration source ordering
- feature flag access through
IFeatureFlagAccessor - named options registration through
optionsName - required-section validation through
requireSection - support for default values through delegates and
IConfigurationDefaults<TOptions> - startup validation through standard
IValidateOptions<TOptions>integration - unified typed access through
IConfigurationAccessor<TOptions> - reload governance through
IConfigurationReloadPolicy<TOptions> - typed change notifications through
IOptionsMonitor<TOptions> - diagnostics through
IConfigurationDiagnostics - redacted configuration snapshots through
IConfigurationRedactor - optional Microsoft.Extensions.Logging diagnostics for configuration reload tracking
What it does not contain
- custom replacement for
IConfiguration - custom configuration providers
- feature flag infrastructure
- custom logging provider requirement
Usage
builder.Configuration.UseRaycynixConfigurationSources(options =>
{
options.BaseFileName = "appsettings";
options.EnvironmentName = builder.Environment.EnvironmentName;
options.IncludeUserSecrets = builder.Environment.IsDevelopment();
});
builder.Services.AddRaycynixEnvironment();
builder.Services.AddRaycynixFeatureFlags(builder.Configuration);
builder.Services.AddRaycynixConfiguration<MyOptions>(
builder.Configuration,
requireSection: true,
configureDefaults: options =>
{
options.TimeoutSeconds = 30;
});
builder.Services.AddRaycynixConfigurationValidator<MyOptions, MyOptionsValidator>();
builder.Services.AddRaycynixConfigurationReloadPolicy<MyOptions>(context =>
{
return ConfigurationReloadResult.Reject("MyOptions cannot be changed at runtime.");
});
builder.Services.AddRaycynixConfigurationChangeHandler<MyOptions>(
static (context, cancellationToken) =>
{
Console.WriteLine($"Configuration changed: {context.ChangedAtUtc:O}");
return ValueTask.CompletedTask;
});
builder.Services.ConfigureRaycynixConfigurationDiagnostics(options =>
{
options.MaxReloadHistoryPerOptions = 10;
});
appsettings.json
Typed options bind from a section named after the options type by default:
{
"MyOptions": {
"Value": "from-config",
"TimeoutSeconds": 30
},
"FeatureFlags": {
"Flags": {
"NewDashboard": true,
"UseFastCache": false
}
}
}
You can override the section name explicitly when needed:
builder.Services.AddRaycynixConfiguration<MyOptions>(
builder.Configuration,
sectionName: "MyFeatureArea:MyOptions");
Named options can be registered by passing optionsName:
builder.Services.AddRaycynixConfiguration<MyOptions>(
builder.Configuration,
sectionName: "Tenants:Primary",
optionsName: "Primary");
IConfigurationAccessor<TOptions>.Get("Primary") returns the current approved snapshot for that named options instance.
Applying Runtime Reload Rules
Use runtime change handling in this order:
- register the typed options model with
AddRaycynixConfiguration<TOptions>(...) - register a validator if the options must be valid on startup
- register a reload policy if runtime updates must be limited
- register one or more change handlers for the updates that are actually allowed
Example:
builder.Services.AddRaycynixConfiguration<CacheOptions>(builder.Configuration);
builder.Services.AddRaycynixConfigurationReloadPolicy<CacheOptions>(context =>
{
if (context.Previous.ConnectionString != context.Current.ConnectionString)
{
return ConfigurationReloadResult.Reject(
"CacheOptions.ConnectionString cannot be changed at runtime.");
}
return ConfigurationReloadResult.Apply();
});
builder.Services.AddRaycynixConfigurationChangeHandler<CacheOptions>(
static (context, cancellationToken) =>
{
Console.WriteLine(
$"Cache options reloaded at {context.ChangedAtUtc:O}. New TTL: {context.Current.DefaultTtlSeconds}");
return ValueTask.CompletedTask;
});
In this example:
- the options are still reloadable
- connection string changes are rejected
- allowed changes continue to flow through the registered handlers
By default, the package binds the section named after the options type, for example MyOptions.
You can override the section name explicitly when needed.
Registered validators run through the standard Options validation pipeline and are enforced on startup through ValidateOnStart().
AddRaycynixConfiguration<TOptions>(...) also registers IConfigurationAccessor<TOptions> so application services can read the current typed configuration without directly depending on IOptionsMonitor<TOptions>.
Example:
public class MyService(IConfigurationAccessor<MyOptions> configurationAccessor)
{
public void Execute()
{
var options = configurationAccessor.Current;
Console.WriteLine(options.TimeoutSeconds);
}
}
Reload policies are evaluated before change handlers are notified. A policy can apply, reject, ignore, or mark a runtime change as requiring restart.
When a runtime change is rejected, IConfigurationAccessor<TOptions> continues to expose the last approved configuration snapshot.
Configuration change handlers are triggered through the standard IOptionsMonitor<TOptions> pipeline when reloadable sources produce updated option values.
You can also declare simple runtime reload rules directly on properties:
public class CacheOptions
{
[ConfigurationReloadBehavior(ConfigurationReloadBehavior.Reject)]
public string ConnectionString { get; set; } = string.Empty;
public int DefaultTtlSeconds { get; set; }
}
When a property marked with Reject changes, the runtime update is rejected automatically before handlers are called.
Diagnostics and Redaction
IConfigurationDiagnostics exposes registered options, retained reload decisions, and redacted snapshots:
var diagnostics = app.Services.GetRequiredService<IConfigurationDiagnostics>();
var registrations = diagnostics.GetRegistrations();
var reloads = diagnostics.GetReloads();
var snapshot = diagnostics.GetRedactedSnapshot<MyOptions>();
Diagnostics behavior can be configured globally:
builder.Services.ConfigureRaycynixConfigurationDiagnostics(options =>
{
options.EnableSnapshots = true;
options.MaxReloadHistoryPerOptions = 10;
});
The default redactor hides common sensitive keys such as passwords, tokens, API keys, private keys, authorization values, and connection strings. Applications can replace it with a custom implementation:
builder.Services.AddRaycynixConfigurationRedactor((key, value) =>
{
return key.Contains("license", StringComparison.OrdinalIgnoreCase)
? "***"
: value;
});
Logging
The package uses the standard Microsoft.Extensions.Logging.ILogger<T> abstraction when a logger is available. Logger dependencies are optional, so the package can run without registering a logging provider. It does not require Raycynix.Extensions.Logging; any Microsoft-compatible logging provider can receive the events.
Runtime configuration reload tracking writes operational decisions at Information and Warning, handler failures at Error, and detailed lifecycle diagnostics at Debug. Configuration validation and diagnostics snapshot access also emit Debug/Warning events without logging configuration values.
Enable Debug logs for this package when troubleshooting registrations, validation, reload policy decisions, diagnostics snapshots, or change handler execution:
{
"Logging": {
"LogLevel": {
"Raycynix.Extensions.Configuration": "Debug"
}
}
}
Feature Flags
Use the standard FeatureFlags section to store boolean feature toggles:
{
"FeatureFlags": {
"Flags": {
"NewDashboard": true,
"UseFastCache": false
}
}
}
Register the feature flags accessor:
builder.Services.AddRaycynixFeatureFlags(builder.Configuration);
Use it in application code:
public class DashboardService(IFeatureFlagAccessor featureFlags)
{
public bool UseNewDashboard()
{
return featureFlags.IsEnabled("NewDashboard");
}
}
Feature flags use the same configuration pipeline as the rest of the package, so they can also participate in reloadable sources.
The standard source order is:
appsettings.jsonappsettings.{Environment}.json- user secrets when enabled
- environment variables
- command-line arguments
The standard environment names are:
DevelopmentTestingStagingProduction
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 (>= 10.0.9)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.9)
- Microsoft.Extensions.Configuration.CommandLine (>= 10.0.9)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.9)
- Microsoft.Extensions.Configuration.Json (>= 10.0.9)
- Microsoft.Extensions.Configuration.UserSecrets (>= 10.0.9)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.9)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.9)
- Microsoft.Extensions.Options (>= 10.0.9)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.9)
- Raycynix.Extensions.Configuration.Abstractions (>= 2.2.0)
NuGet packages (12)
Showing the top 5 NuGet packages that depend on Raycynix.Extensions.Configuration:
| Package | Downloads |
|---|---|
|
Raycynix.Extensions.Logging
Structured logging registration, Serilog-based host integration, typed logger adapters, and configurable console logging for Raycynix applications. |
|
|
Raycynix.Extensions.Database
Core Raycynix EF Core database infrastructure with shared DbContext registration, custom context support, model assembly discovery, provider validation, initialization, and model-cache integration. |
|
|
Raycynix.Extensions.Security
Core security services, typed security configuration, shared identity context handling, and application-level authorization composition for Raycynix applications. |
|
|
Raycynix.Extensions.Messaging
Transport-agnostic messaging registration, dispatch, direct requests, observability, scoped envelope factories, and outbox/inbox reliability foundations for Raycynix applications. |
|
|
Raycynix.Extensions.Database.PostgreSql
PostgreSQL provider integration for Raycynix.Extensions.Database with AddPostgreSql registration, provider-specific validation, Npgsql connection-string composition, and EF Core UseNpgsql configuration. |
GitHub repositories
This package is not used by any popular GitHub repositories.
v2.2.0 starts unified versioning for Raycynix packages and adds optional Microsoft.Extensions.Logging diagnostics for validation, diagnostics snapshots, and configuration reload tracking.