zoukankan      html  css  js  c++  java
  • net core 获取配置文件

    IConfiguration服务是net core 默认依懒注入的一个对象 直接注入(推荐使用)

      新建控制器 然后构造函数直接注入

     [Route("api/[controller]")]
        public class ValuesController : Controller
        {
            private IConfiguration _configuration { get; }
    
            public ValuesController(IConfiguration configuration)
            {
                _configuration = configuration;
            }
            // GET: api/values
            [HttpGet]
            public IEnumerable<string> Get()
            {
                return new string[] { _configuration["appSettings:SvcUrl"] };
            }
        }

    创建一个ConfigurationBuilder 来加载配置文件

      var builder = new ConfigurationBuilder()
                    .SetBasePath(Directory.GetCurrentDirectory())
                   .AddJsonFile("appsettings.json");
                var configuration = builder.Build();
    
                string SvcUrl = configuration["appSettings:SvcUrl"];
  • 相关阅读:
    python之基础2
    python之文件2
    python之入门2
    python之入门
    python之多并发2
    python之面向对象2
    python之MySQL系列
    python之文件
    python之多并发
    Google身份验证器详解
  • 原文地址:https://www.cnblogs.com/zhaops/p/10670299.html
Copyright © 2011-2022 走看看