appsettings.json如下

{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
},
"AllowedHosts": "*"
},
"ConfigSetting": {
"Ctu": ,
"Btu": "Btu",
"Atu": "Atu"
}
}

建立实体ConfigSetting

    public class ConfigSetting
{
public int Ctu { get; set; }
public string Btu { get; set; }
public string Atu { get; set; }
}

Startup配置

        public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.Configure<ConfigSetting>(Configuration.GetSection("ConfigSetting"));
}

Controller配置

    [Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
private readonly IOptions<ConfigSetting> _ConfigSettingt;
public ValuesController(IOptions<ConfigSetting> ConfigSetting)
{
_ConfigSettingt = ConfigSetting;
}
[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
return _ConfigSettingt.Value.Atu;
}
}

.net core 中如何读取 appsettings.json 相关配置的更多相关文章

  1. .net core 中如何运用 appsettings.json 进行配置开发、生产不同配置

    .net core 默认会有 appsettings.Development.json 文件,这是根据ASPNETCORE_ENVIRONMENT来读取的. 新建架构appsettings.Produ ...

  2. .NET Core类库项目中如何读取appsettings.json中的配置

    这是一位朋友问我的问题,写篇随笔回答一下.有2种方法,一种叫丑陋的方法 —— IConfiguration ,一种叫优雅的方法 —— IOptions . 1)先看丑陋的方法 比如在 RedisCli ...

  3. .Net Core 读取appsettings.json的配置

    在.net core中是没有*.config 文件的 配置文件都是*.json 1.在project.json里下面这行代码 "Microsoft.Extensions.Options.Co ...

  4. ASP.NET CORE读取appsettings.json的配置

    如何在appsettings.json配置应用程序设置,微软给出的方法:https://docs.microsoft.com/en-us/aspnet/core/fundamentals/config ...

  5. .NET Core 类库中读取appsettings.json

    { "Logging": { "IncludeScopes": false, "LogLevel": { "Default&quo ...

  6. Asp .Net Core 读取appsettings.json配置文件

         Asp .Net Core 如何读取appsettings.json配置文件?最近也有学习到如何读取配置文件的,主要是通过 IConfiguration,以及在Program中初始化完成的. ...

  7. asp.net core读取appsettings.json,如何读取多环境开发配置

    摘要 在读取appsettings.json文件中配置的时候,觉得最简单的方式就是使用asp.net core注入的方式进行读取了. 步骤 首先根据配置项的结构定义一个配置类,比如叫AppSettin ...

  8. Asp.Net Core 进阶(一) —— 读取appsettings.json

    我们以前在Asp.Net MVC中使用 System.Configuration.ConfigurationManager 来读取web.config文件.但是Asp.Net Core MVC已经没有 ...

  9. 干货:.net core实现读取appsettings.json配置文件(建议收藏)

    看好多人不懂在.NET CORE中如何读取配置文件,我这里分两篇,这一篇介绍怎样通过appsettings.json配置读取文件信息.这里我会教大家两种方式: 第一种直接放到通用类库,那里想调往那调. ...

随机推荐

  1. CCF_201409-1_相邻数对

    水. #include<iostream> #include<cstdio> #include<algorithm> using namespace std; in ...

  2. Loj 6002 最小路径覆盖(最大流)

    题意: 求不相交的最小路径覆盖 思路: 连边跑二分图,匹配一条边相当于缩了一条边,答案为n-maxflow 如果是求可以相交的最小路径覆盖的话,先用Floyd跑出可达矩阵,然后所有可达的点连边跑二分图 ...

  3. 题解 bzoj1954【Pku3764 The xor – longest Path】

    做该题之前,至少要先会做这道题. 记 \(d[u]\) 表示 \(1\) 到 \(u\) 简单路径的异或和,该数组可以通过一次遍历求得. \(~\) 考虑 \(u\) 到 \(v\) 简单路径的异或和 ...

  4. LwIP与IPv6

    2.0.0中才开始支持IPv6,在此版本中改写了SNMP,但还没有IPv6的统计量.目前最新版本是2.0.2,其中SNMP也没有IPv6统计量(哪些?与IP的统计量有何区别?) 1.4.1中虽然有ip ...

  5. 外网访问oracle 很慢

    一台oracle服务器  对外网开放服务,外网连接后查询速度很慢,内网查询非常快.应该是这个cisco的防火墙有问题,查了很久 没有找到原因. 临时解决方法,在内网再建一台 跳转服务器,外网查询数据库 ...

  6. NOIP2012-------跳石头(C语言)

    #include<stdio.h> ]; int check(long mid, long n, long m) { long last, i, ans; last = a[]; ans ...

  7. 珠峰-cookie相关的东西

    ####  md5 #### #####

  8. h5笔记2

    •离线缓存: html配置manifest属性,cache.manifest是缓存配置文件 <html lang="zh-CN" manifest="cache.m ...

  9. JS求1到100的累计值

    sum=0 for(i=1;i<=100;i++) { sum+=i } alert(sum)   作者:kerwin-chyl 文章链接:https:////www.cnblogs.com/k ...

  10. WPF 原生绑定和命令功能使用指南

    WPF 原生绑定和命令功能使用指南 魏刘宏 2020 年 2 月 21 日 如今,当谈到 WPF 时,我们言必称 MVVM.框架(如 Prism)等,似乎已经忘了不用这些的话该怎么使用 WPF 了.当 ...