asp.net core appsetting.json bind reading

appsettings.json having:

"AppSettings": { "AzureConnectionKey": "***", "AzureContainerName": "**", "NumberOfTicks": 621355968000000000, "NumberOfMiliseconds": 10000, "SelectedPvInstalationIds": [ 13, 137, 126, 121, 68, 29 ], "MaxPvPower": 160, "MaxWindPower": 5745.35 },

I also have classes to store them:

public class AppSettings { public string AzureConnectionKey { get; set; } public string AzureContainerName { get; set; } public long NumberOfTicks { get; set; } public long NumberOfMiliseconds { get; set; } public int[] SelectedPvInstalationIds { get; set; } public decimal MaxPvPower { get; set; } public decimal MaxWindPower { get; set; } }

Then enable DI, then in use in Startup.cs:

services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));

Is there any way to change and save MaxPvPower, and MaxWindPowerfrom the controller?

I try to use

private readonly AppSettings _settings; public HomeController(IOptions<AppSettings> settings) { _settings = settings.Value; } 

Guess you like

Origin www.cnblogs.com/tianfengcc/p/12587683.html