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;
    }
    
  • 相关阅读:
    解析包含空格的字符串
    机器学习实战之Logistic回归
    复杂的数据类型
    k-近邻算法
    C&C++
    位运算
    文件操作
    结构体与共用体
    预处理-04-#if defined和#if !defined
    预处理-03-文件包含、条件编译、小结
  • 原文地址:https://www.cnblogs.com/tianfengcc/p/12587683.html
Copyright © 2011-2022 走看看