• 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;
    }
    
  • 相关阅读:
    HashMap put get 源码解析
    HashMap 源码
    配置spring boot请求的入参和出参json数据格式
    配置idea的注释模板
    基本数据类型
    Linux命令系列之
    Linux命令系列之
    Linux命令系列之
    Linux命令系列之
    Linux命令系列之
  • 原文地址:https://www.cnblogs.com/tianfengcc/p/12587683.html
Copyright © 2020-2023  润新知