结合了好几个哥们的写法,最终我使用了这个版本,现在把我这个版本的写出来,如果该版本和您的版本类似或者一样,那可能是借鉴您的

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using System;
using System.Collections.Generic;
using System.Text; namespace Common
{
public class AppSettings
{
public static IConfiguration Configuration { get; set; } public static void Initial(IConfiguration configuration)
{
Configuration = configuration;
} /// <summary>
/// 封装要操作的字符
/// </summary>
/// <param name="sections"></param>
/// <returns></returns>
public static string app(params string[] sections)
{
try
{
var val = string.Empty;
for (int i = 0; i < sections.Length; i++)
{
val += sections[i] + ":";
} return Configuration[val.TrimEnd(':')];
}
catch (Exception)
{
return "";
}
}
}
}

然后我们需要在strartup里面为这个Configuration赋值

 public Startup(IConfiguration configuration, IWebHostEnvironment env)
{
AppSettings.Initial(configuration);
}

在上面这个里面我看见有个老哥的写法是下面这种,但是经过我的测试,直接按照我的这种写法操作也是可以的

该图借鉴于:https://www.cnblogs.com/wangpengzong/p/12700974.html

最新文章

  1. Java 第7章 数组
  2. oracle max()函数和min()函数
  3. CODEVS 3000公路修建问题
  4. MVC ViewEngine视图引擎解读及autofac的IOC运用实践
  5. 程序员求职之道(《程序员面试笔试宝典》)之求职有用网站及QQ群一览表
  6. 【Machine Learning】Mahout基于协同过滤(CF)的用户推荐
  7. DDCTF-2019
  8. C语言博客作业06——结构体&amp;文件
  9. 几个js框架
  10. ubuntun 18.04 安装google浏览器
  11. eclipse 安装配置
  12. PHP中文转拼音函数
  13. 跨域请求中预检请求options之坑
  14. QL Server 高可用性(一)AlwaysOn 技术
  15. Brainfuck解析器(Python)
  16. webapp定位
  17. Linux学习1-Xshell连接阿里云ECS服务器
  18. oracle内存结构
  19. Markdown中的表格
  20. Intellij Idea 将java项目打包成jar

热门文章

  1. C++中tuple类型
  2. Elasticsearch常用API
  3. javascript处理HTML的Encode(转码)和解码(Decode)
  4. Nginx常见的错误配置
  5. CVE-2018-2628-WLS Core Components 反序列化
  6. OpenCV 之 角点检测
  7. VScode 自定义用户代码块
  8. 安装RPM包或者源码包
  9. 【linux】驱动-6-总线-设备-驱动
  10. Centos7安装Nacos单机模式以及集群模式(包含nignx安装以及实现集群)的相关配置