C# Core1.1 版本 AppSettings 使用方法
2017-05-05 11:34
239 查看
1:在AppSettings.json 里书写格式为:"AppSettings":{"key":"value","key":"value"};
2::Start up.cs里新增配置
public void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
services.AddMvc();
}
3:新建一个AppSettings.cs 封装 所需要的Key;
4:管理NUGET包安装以下
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.1",
"Microsoft.Extensions.Configuration.Json": "1.1.1“
5:在所需要的地方加代码
public clss XXXController:Controller
{ private AppSettings AppSettings { get; set; }
public HomeController(IOptions<AppSettings> settings)
{
AppSettings = settings.Value;
}
}
6:现在就可以在其他地方调用了
例如:var x = AppSettings.Key
2::Start up.cs里新增配置
public void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
services.AddMvc();
}
3:新建一个AppSettings.cs 封装 所需要的Key;
4:管理NUGET包安装以下
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.1",
"Microsoft.Extensions.Configuration.Json": "1.1.1“
5:在所需要的地方加代码
public clss XXXController:Controller
{ private AppSettings AppSettings { get; set; }
public HomeController(IOptions<AppSettings> settings)
{
AppSettings = settings.Value;
}
}
6:现在就可以在其他地方调用了
例如:var x = AppSettings.Key
相关文章推荐
- One time Password的使用方法C#版本
- EntityFramework Core 1.1 Add、Attach、Update、Remove方法如何高效使用详解
- CoreLocation 的基本使用 以及定位 指南针的实现 (附加: 系统版本适配的方法,和后台更新用户位置的方法及注意)
- C#编译器优化那点事 c# 如果一个对象的值为null,那么它调用扩展方法时为甚么不报错 webAPI 控制器(Controller)太多怎么办? .NET MVC项目设置包含Areas中的页面为默认启动页 (五)Net Core使用静态文件 学习ASP.NET Core Razor 编程系列八——并发处理
- ASP.NET core Web中使用appsettings.json配置文件的方法
- C#中使用OpenGL:(五)1.1版本的OpenGL函数
- c# .net core HttpWebRequest 使用Headers[]方法代替UserAgent
- 在C# 2.0版本中使用Extensions方法
- EntityFramework Core 1.1 Add、Attach、Update、Remove方法如何高效使用详解
- ASP.NET Core2.0 使用VSCode 版本1.13.1工具 开发控制台运行出现中文乱码问题及解决方法
- C# .net core XmlDocument 使用Load和Save方法
- 百度地图和高德地图坐标系的互相转换 四种Sandcastle方法生成c#.net帮助类帮助文档 文档API生成神器SandCastle使用心得 ASP.NET Core
- EntityFramework Core 1.1 Add、Attach、Update、Remove方法如何高效使用详解
- EntityFramework Core 1.1 Add、Attach、Update、Remove方法如何高效使用详解
- EntityFramework Core 1.1 Add、Attach、Update、Remove方法如何高效使用详解
- windows server 2003中使用cocos2d-x,提示OpenGL版本为1.1,要更新驱动,解决方法
- asp.net c#中使用FCKeditor的方法,版本2.66
- 关于mac注册机core keygen在10.12及以上版本不能使用的解决方法
- asp.net能实现身份认证的EMAIL发送方法(c#版本)
- 在C#中使用异步Socket编程实现TCP网络服务的C/S的通讯构架(二)----使用方法