KhaosCode.MultiApp.Settings
1.0.3
See the version list below for details.
dotnet add package KhaosCode.MultiApp.Settings --version 1.0.3
NuGet\Install-Package KhaosCode.MultiApp.Settings -Version 1.0.3
<PackageReference Include="KhaosCode.MultiApp.Settings" Version="1.0.3" />
<PackageVersion Include="KhaosCode.MultiApp.Settings" Version="1.0.3" />
<PackageReference Include="KhaosCode.MultiApp.Settings" />
paket add KhaosCode.MultiApp.Settings --version 1.0.3
#r "nuget: KhaosCode.MultiApp.Settings, 1.0.3"
#:package KhaosCode.MultiApp.Settings@1.0.3
#addin nuget:?package=KhaosCode.MultiApp.Settings&version=1.0.3
#tool nuget:?package=KhaosCode.MultiApp.Settings&version=1.0.3
Khaos Settings
High-concurrency, multi-application hierarchical settings store + EF Core provider + dynamic configuration reload for .NET 9.
Global < Application < Instance precedence; optimistic concurrency enforced with SQL Server
rowversion+ filtered unique indexes (NULL?safe) preventing duplicate logical rows.
Key Features
- Hierarchical scoping: Global / Application / Instance layering with overwrite semantics (no deep merge; last writer wins by scope precedence).
- Optimistic concurrency: Mandatory
RowVersionfor every update/delete (lost update protection). - Atomic Upsert (SQL Server):
UPDLOCK, HOLDLOCKguarded update-or-insert with retry semantics (insert collision returnsMissingRowVersionto force client revise path). - Deterministic reload detection: Fast triplet signature (RowCount, MaxRowVersion, KeyChecksum) + full SHA2-256 hash with ordered aggregation of value + metadata.
- Binary payload support separated from text tree (efficient
IConfigurationbinding + dedicatedIBinarySettingsAccessor). - Append-only audit history (old/new value + rowversion before/after) with safe rollback semantics.
- Scoped secret handling + masked logging (no plaintext secrets in structured logs unless opted in).
- Metrics hooks (
IMetricsRecorder) & health reporter (last success, failure streak, snapshot hash snippet). - CLI for CRUD, history, rollback, export/import.
Projects
| Project | Purpose |
|---|---|
| Khaos.Settings.Abstractions | Public contracts, models, errors, options |
| Khaos.Settings.Data | EF Core entities & DbContext (no migrations) |
| Khaos.Settings.Core | Domain services (CRUD, history, binary accessor) |
| Khaos.Settings.Provider | Configuration provider + background reload |
| Khaos.Settings.Encryption | Placeholder encryption provider (NoOp) |
| Khaos.Settings.Metrics | In-memory & no-op metrics recorder |
| Khaos.Settings.Cli | Console CLI for managing settings |
| Khaos.Settings.Sample | Minimal ASP.NET sample |
| Khaos.Settings.ConsoleSample | Generic Host console sample (snapshot monitor) |
SQL Schema
See scripts/create_tables.sql (excerpt below):
-- Filtered unique indexes for NULL-safe natural key enforcement
CREATE UNIQUE INDEX UX_Settings_Global_Key ON dbo.Settings([Key]) WHERE ApplicationId IS NULL AND InstanceId IS NULL;
CREATE UNIQUE INDEX UX_Settings_App_Key ON dbo.Settings(ApplicationId, [Key]) WHERE ApplicationId IS NOT NULL AND InstanceId IS NULL;
CREATE UNIQUE INDEX UX_Settings_Instance_Key ON dbo.Settings(ApplicationId, InstanceId, [Key]) WHERE ApplicationId IS NOT NULL AND InstanceId IS NOT NULL;
Full script includes audit table dbo.SettingsHistory and indices for history traversal.
Getting Started
- Create tables (run script):
sqlcmd -S . -d YourDb -i scripts/create_tables.sql - Register provider (ASP.NET):
builder.Configuration.AddKhaosMultiAppSettings(o => { o.ApplicationId = "orders-service"; o.InstanceId = Environment.MachineName; o.ConnectionString = builder.Configuration.GetConnectionString("SettingsDb"); o.EnableDecryption = false; // enable + register real provider when ready }); builder.Services.AddKhaosSettingsServices(builder.Configuration); - Consume settings:
- Bind via
IConfiguration(text values only) or strongly typed options. - Fetch binary with
IBinarySettingsAccessor.
- Bind via
- Perform CRUD via
ISettingsService(must supplyExpectedRowVersionon update/delete):var created = await svc.UpsertAsync(new SettingUpsert { Key = "FeatureX:Enabled", Value = "true", ChangedBy = user }); var updated = await svc.UpsertAsync(new SettingUpsert { Key = created.Key, Value = "false", ChangedBy = user, ExpectedRowVersion = created.RowVersion }); - Rollback a change:
await history.RollbackAsync("FeatureX:Enabled", versionIndex: 2, changedBy: user);
Console Sample (Generic Host)
Khaos.Settings.ConsoleSample demonstrates:
- Adding the provider to a generic host.
- Monitoring snapshot reloads with
ISettingsSnapshotSource+ change token. - Printing diffs (added/updated/removed keys).
Run:
cd Khaos.Settings.ConsoleSample
dotnet run -- --application demo --connection "Server=.;Database=DemoSettings;Trusted_Connection=True;TrustServerCertificate=True"
Metrics
| Metric | Description |
|---|---|
khaos_settings_reload_success_total |
Successful reloads |
khaos_settings_reload_skipped_total |
Fast-path unchanged |
khaos_settings_reload_failure_total |
Reload failures |
khaos_settings_validation_failure_total |
Validation failures (reload) |
khaos_settings_reload_concurrency_conflict_total |
CRUD concurrency conflicts |
khaos_settings_poll_failures_consecutive |
Consecutive poll failures (gauge) |
Error Codes
| Code | Scenario |
|---|---|
MissingRowVersion |
Update/delete attempted without expected rowversion |
ConcurrencyConflict |
Rowversion mismatch on update/delete |
DuplicateKey |
Natural key uniqueness violated |
RollbackConflict |
Current row changed beyond rollback target |
ValidationFailure |
Invalid request or rollback XOR violation |
Export / Import (CLI)
# export (secrets masked by default)
settings-cli --application app --connection "..." export --file out.json
# import dry-run
settings-cli --application app --connection "..." import --file out.json
# apply
settings-cli --application app --connection "..." import --file out.json --apply
Roadmap (Abbrev.)
- Deterministic encryption & plaintext hash column.
- Push notifications for near-real-time reload.
- Health endpoint & status CLI command.
- Manifest/schema generator & advanced export (binary / rowversion).
License
TBD.
Created from implementation spec in Specification.md.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 was computed. 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. |
-
net9.0
- KhaosCode.Time (>= 1.0.0)
- Microsoft.Extensions.Configuration (>= 9.0.0)
- Microsoft.Extensions.Hosting (>= 9.0.0)
- Microsoft.Extensions.Options (>= 9.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.