首页 > Web开发 > 详细

netcore使用IOptions

时间:2020-07-08 16:06:31      阅读:68      评论:0      收藏:0      [点我收藏+]
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "HC": {
    "Redis": {
      "aa": "1"
    },
    "DB": {
      "bb": 2
    }
  }
}

startup.cs

services.Configure<Test>(Configuration.GetSection("HC"));
public class Test
    {
        public Redis Redis { get; set; }
        public DB DB { get; set; }
    }
    public class Redis
    {
        public string aa { get; set; }
    }
    public class DB
    {
        public string bb { get; set; }
    }
public Test Test { get; set; }

        public api1Controller(IOptions<Test> options)
        {
            Test = options.Value;
        }

 

 

来源  :https://www.cnblogs.com/herocany/p/netcore_ioptions.html

netcore使用IOptions

原文:https://www.cnblogs.com/shy1766IT/p/13267027.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!