asp.netコアappsetting.jsonバインド読み取り

appsettings.jsonました:

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

私はまた、それらを格納するためのクラスがあります。

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; } }

そして、その後、Startup.csでの使用には、DIを有効にします。

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

変更し、保存する方法はありますMaxPvPowerし、MaxWindPowerコントローラから?

私が使用しよう

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

おすすめ

転載: www.cnblogs.com/tianfengcc/p/12587683.html