修改appsetting

最近用Identity4所以需要做一个配置项项目

{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
},
"Indentity": {"Center": "",//这部分就是要取的
"ApiCenter": ""
}
}

在startup中获取

首先我们要从 Indentity中 获取center当中的数据

这部分比较简单只要在startup 中的ConfigureServices 获取 Indentity下的Center

this.Configuration["Indentity:Center"]

就这么一句话就可以获取到了

将内容注入到管道中

1.创建一个model

    public class IndentitySettingModel
{
public string Center { get; set; }
public string ApiCenter { get; set; }
}

2.在startup中注入到管道当中

services.Configure<Utility.HelperModel.IndentitySettingModel>(this.Configuration.GetSection("Indentity"));

兄弟。这样就注入到管道当中了。接下来我们就可以去controller中获取 了

在controller中获取

        /// <summary>
/// 获取AccessToken
/// </summary>
/// <returns></returns>
public string GetAccessToken(IOptions<IndentitySettingModel> settings)
{
return settings.Center;
}

恩很 就是这样 就可以获取的到了。

最详细的config引用

刚才有几个朋友和我说 。我干的很漂亮纯属糊弄人的文章。

好的。 我重新写一下吧。

我把所有需要引用DLL 给大家贴图吧。太多了。

算了,还是打出来吧。

Microsoft.Extensions.Configuration
Microsoft.Extensions.Configuration.Abstractions
Microsoft.Extensions.Configuration.Json
Microsoft.Extensions.DependencyInjection
Microsoft.Extensions.Options
Microsoft.Extensions.Options.ConfigurationExtensions

把这些 nuget引用

编写Help类

    public class ConfigurationUtil
{ public static readonly IConfiguration Configuration; static ConfigurationUtil()
{
Configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", true)
.Build();
} public static T GetSection<T>(string key) where T : class, new()
{
var obj = new ServiceCollection()
.AddOptions()
.Configure<T>(Configuration.GetSection(key))
.BuildServiceProvider()
.GetService<IOptions<T>>()
.Value;
return obj;
} public static string GetSection(string key)
{
return Configuration.GetValue<string>(key);
}
}

调用方法

ConfigurationUtil.GetSection("MongoDb:ConnectionString")

骂人部分

天天让我写。天天没人点赞!

后续

创建了一个QQ群希望有志之士可以加一下

点击链接加入群聊【.Net Core研究团】:https://jq.qq.com/?_wv=1027&k=5298dNv

最新文章

  1. java md5
  2. 原生Ajax封装随笔
  3. Matlab画图,坐标轴范围设置和间隔设置
  4. android自定义控件(7)-获取自定义ImageView的src属性
  5. Android NDK开发入门实例
  6. MYSQL例题合集
  7. Android中XML格式数据的简单使用
  8. opencv 2.46与visual studio 2012 配置方法
  9. redis存储session配制方法
  10. 一道经典的C++结构体的题目
  11. Delphi遍历文件夹及子文件夹(可查找固定格式文件)
  12. jQuery事件触发和参数传递
  13. eclipse启动tomcat不能访问解决
  14. leetcode 169 Majority Element 冰山查询
  15. SSM-Spring-12:Spring中NameMatchMethodPointcutAdvisor名称匹配方法切入点顾问
  16. 基本数据对象(int,float,str)
  17. ClickHouse之访问权限控制
  18. 【Linux】创建不可修改文件
  19. Jquery easyui 重置按钮,easyui 清空表单,Jquery easyui 重置表单
  20. ubuntu16.4中开启vncserver进行远程桌面

热门文章

  1. vue-learning:10-template-ref
  2. CF1151FSonya and Informatics
  3. HDU - 3530 Subsequence (单调队列)
  4. TCPIP四层模型和OSI七层模型对应表
  5. 事件驱动框架EventNext之线程容器
  6. windows7下mysql8.0.18部署安装
  7. vue项目创建步骤 和 路由router知识点
  8. Redis事务、持久化、发布订阅
  9. 【题解】NOIP2016 提高组 简要题解
  10. 「USACO08JAN」电话线Telephone Lines 解题报告