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;
    }
    
  • 相关阅读:
    student
    super
    java 浮点数
    视图
    日期转换函数
    左外连接,右外连接,全外连接,自然连接,自连接区别
    Python中sys.argv[ ]的用法
    0 Scala
    统计字符串字符个数
    3个链表排序整合到一起
  • 原文地址:https://www.cnblogs.com/tianfengcc/p/12587683.html
Copyright © 2011-2022 走看看