I am working on Asp.Net Core app
I want to change the configuration settings after running the application
I am using IOptionsMonitor, but it is not detecting changes
In Startup.cs -> Configuration() method I have
services.Configure<Config>(Configuration.GetSection("someConfig"));
In a different class where these config settings are read, I wrote something like
var someConfig= serviceProvider.GetRequiredService<IOptionsMonitor<Config>>();
But when I change the configuration file (Json File), the change is not detected, and someConfig does not change.
Config POCO class:
public class Config
{
public string name {get; set;}
//More getters and setters
}
Edit:
services.AddSingleton<ConfigHelpers>;
I am using a singleton object in which I am trying to read the config. It works fine if its not a snigleton. Is there a way to change the config even in a singleton object ?
in ConfigHelpers.cs
var someConfig= serviceProvider.GetRequiredService<IOptionsMonitor<Config>();
since it is defined as singleton in Startup.cs, changes made to Config are not reflected.
IOptionsMonitor
withIOptionsSnapshot
? – Repair