shreesharao / aspnetcore-ConsoleToWeb

Convert Console project to web project for understanding the working of asp.net core mvc
0 stars 0 forks source link

how to persist configuration changes in appsettings.json file #6

Closed shreesharao closed 6 years ago

shreesharao commented 6 years ago

how to persist configuration changes in appsettings.json file?

shreesharao commented 6 years ago

Basically you can set the values in IConfiguration like this:

IConfiguration configuration = ...
// ...
configuration["key"] = "value";

The issue there is that e.g. the JsonConfigurationProvider does not implement the saving of the configuration into the file. As you can see in the source it does not override the Set method of ConfigurationProvider.

You can create your own provider and implement the saving there.Here is an example how to do it.