ASP.NET Core profile Savin

I read the appsetting.json configuration of ASP.NET Core in the following ways

services.Configure<MyConfigs>(Configuration.GetSection("MyConfigsSection"));

the configuration is read out and injected into Controller or Class using
, but in this way, it seems that the data can only be read out, and the new value cannot be written back to the "MyConfigsSection" of appsetting.json

.

how to write the new value back or is there any better way to save the program configuration (readable and writable)

Thank you very much


just modify the appsetting.json file directly, which is hot overloaded by default.
for example, add or delete JObject.Parse and use IO API ( IO.File.WriteAllText ) to write the ToString content of the previous object, which includes an option of whether to indent or not. You can also directly use Serialize of JsonSerializer .

Best practices for program configuration, depending on the application.

The configuration options of

ASP.NET Core are very flexible. You can first check out the official documentation:
https://docs.microsoft.com/zh.

.
Menu