I just started using .NET Core and JSON for my app settings files. I can see it's very easy to retrieve values from my appsettings.json file using the following...
IConfigurationRoot _config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.Build();
// Determine from args the following...
// 1) Transport: FTP (default), WebAPI
// 2) Run as service: True, False (default)
if (!Enum.TryParse<TransportMethods>(_config.GetValue<string>("TransportMethod"), out TransportMethods tMethod))
tMethod = TransportMethods.FTP;
Now I would like the application to be able to save some "user settings" to the same appsettings.json file. What's the best way to save user settings to appsetting.json? From what I'm reading the IConfigurationRoot does not allow writing, it's read-only. So is there another way to save my settings to appsettings.json?