The main configuration root interface.
Observable stream of configuration changes.
IObservable<ConfigChangeEvent> ConfigChanges { get; }
Get a configuration value.
string? Get(string key)
T? Get<T>(string key)
Check if a key exists.
bool Exists(string key)
Get a configuration section.
ICfgSection GetSection(string key)
Set a configuration value.
void Set(string key, string? value, int? targetLevel = null)
Remove a configuration key.
void Remove(string key, int? targetLevel = null)
Save pending changes.
Task SaveAsync(int? targetLevel = null, CancellationToken ct = default)
Get multiple values.
IReadOnlyDictionary<string, string?> GetMany(IEnumerable<string> keys)
void GetMany(IEnumerable<string> keys, Action<string, string?> onValue)
Set multiple values.
void SetMany(IEnumerable<KeyValuePair<string, string?>> values, int? targetLevel = null)
Convert to IConfigurationRoot.
IConfigurationRoot ToMicrosoftConfiguration()
// Read
var name = cfg.Get("App:Name");
var port = cfg.Get<int>("App:Port");
// Write
cfg.Set("App:Name", "NewName");
await cfg.SaveAsync();
// Subscribe to changes
cfg.ConfigChanges.Subscribe(e => Console.WriteLine("Changed!"));