Reputation: 196
Imagine the following:
public class FooOptions {
public string FooProperty {get; set;}
}
public class BarOptions {
public string BarProperty {get; set;}
}
public class ConfigureBarOptions : IConfigureOptions<BarOptions> {
private readonly IOptionsMonitor<FooOptions> _fooOptionsMonitor;
public ConfigureBarOptions(IOptionsMonitor<FooOptions> fooOptionsMonitor) {
_fooOptionsMonitor = fooOptionsMonitor;
}
public void Configure(BarOptions options) {
options.BarProperty = _fooOptionsMonitor.CurrentValue.FooProperty;
}
}
// in Startup.cs - bind to a configuration provider that is set to reload
services.Configure<FooOptions>(Configuration);
How can I trigger a reload of BarOptions when FooOptions is reloaded due to an underlying configuration update?
I've played around with various attempts at registering some versions of:
services.AddSingleton<IOptionsChangeTokenSource<BarOptions>>(new ConfigurationChangeTokenSource<BarOptions>(name, config));
I've also tried to think of a way to use ChangeToken or _fooOptionsMonitor.OnChange but haven't seemed to get the right implementation.
Upvotes: 0
Views: 672