zoukankan      html  css  js  c++  java
  • asp.net core 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; }
    }

    然后启用DI,然后在Startup.cs中使用:

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

    有没有什么办法来改变和保存MaxPvPower,并MaxWindPower从控制器?

    我尝试使用

    private readonly AppSettings _settings;
    
    public HomeController(IOptions<AppSettings> settings)
    {
        _settings = settings.Value;
    }
    
  • 相关阅读:
    第一周作业
    第一周作业
    C语言I博客作业07
    C语言I博客作业06
    C语言I博客作业03
    C语言I博客作业04
    c语言|博客作业02
    字段的约束验证
    [转]AS IS ? ??运算符
    BindingManagerBase 跟踪不一致
  • 原文地址:https://www.cnblogs.com/tianfengcc/p/12587683.html
Copyright © 2011-2022 走看看