Reputation: 1137
I used the config in Startup.cs
file (and in also in other).
app.UseCors(options =>
{
options.WithOrigins(Configuration["AllowedCors"]).AllowAnyMethod().AllowAnyHeader();
});
I publish my code (to deploy),
and sometimes, I have to changes my appsettings.json
.
But, seem like it's still getting old value. And I always need to restart my app to getting new value work.
Does anyone have anny idea?
Upvotes: 1
Views: 1317
Reputation: 621
You can use IOptionsSnapshot instead of IOptions for inject settings in the constructor, after set reloadOnChange: true like this answer.
private readonly BranchSettings _settings;
public Constructor(IOptionsSnapshot<BranchSettings> settings)
{
_settings = settings?.Value;
}
Upvotes: 1
Reputation: 493
I'm unsure if this is what you are asking, but when you change appsettings.json on a already running deployment, to load new values you have to restart that deployment.
EDIT: Seems like I was mistaken, Ali gave a simple solution without restarting the application.
Upvotes: 0
Reputation: 99
You should use reloadOnChange: true in your startup file.
public Startup(IWebHostEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
Configuration = builder.Build();
}
Upvotes: 2