• 命令行的配置

       var settings = new Dictionary<string, string>{
      { "name","cyao"},
      {"age",""}
      };
      var builder = new ConfigurationBuilder()
      .AddInMemoryCollection(settings)内存中获取appsettings
      .AddCommandLine(args);
      var configuration = builder.Build();
      Console.WriteLine($"name:{configuration["name"]}");
      Console.WriteLine($"age:{configuration["age"]}");
      Console.ReadLine();
      Console.ReadKey();
    • json文件的配置
      首先新建一个class.json的配置文件
      {
      "classNo": "1",
      "gread": "1",
      "student": [
      {
      "name": "cyao",
      "age": 18
      },
      {
      "name": "jaya",
      "age": 19
      }
      ]
      }

        然后在configuration中注册

 var builder = new ConfigurationBuilder()
.AddJsonFile("class.json")//json文件中获取appsettings
//.AddInMemoryCollection(settings)内存中获取appsettings
.AddCommandLine(args);
var configuration = builder.Build();
Console.WriteLine($"classNo:{configuration["classNo"]}");
Console.WriteLine($"gread:{configuration["gread"]}");
Console.WriteLine($"name:{configuration["student::name"]}");
Console.WriteLine($"age:{configuration["student::age"]}");
Console.WriteLine($"name:{configuration["student::name"]}");
Console.WriteLine($"age:{configuration["student::age"]}");
Console.ReadLine();
Console.ReadKey();
    • 从配置文件文本到C#对象实例的映射-option与Bind

      namespace JwtAuth
      {
      public class JwtSettings
      {
      ///使用者
      public string Issuer { get; set; }
      ///颁发者
      public string Audience { get; set; }
      ///秘钥必须大于16个字符
      public string SecretKey { get; set; }
      } }
      json文件格式如下
      {
      "Logging": {
      "IncludeScopes": false,
      "Debug": {
      "LogLevel": {
      "Default": "Warning"
      }
      },
      "Console": {
      "LogLevel": {
      "Default": "Warning"
      }
      }
      },
      "JwtSettings": {
      "Issuer": "http://locahost:5000",
      "Audience": "http://locahost:5000",
      "SecretKey": "hello world this is my key for cyao"
      }
      }
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Threading.Tasks;
      using Microsoft.AspNetCore.Builder;
      using Microsoft.AspNetCore.Hosting;
      using Microsoft.Extensions.Configuration;
      using Microsoft.Extensions.DependencyInjection;
      using Microsoft.Extensions.Logging;
      using Microsoft.Extensions.Options; namespace JwtAuth
      {
      using Microsoft.AspNetCore.Authentication.JwtBearer;
      using Microsoft.AspNetCore.Authorization;
      using Microsoft.IdentityModel.Tokens; public class Startup
      {
      public Startup(IConfiguration configuration)
      {
      Configuration = configuration;
      } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container.
      public void ConfigureServices(IServiceCollection services)
      {
      //将配置文件读取到settings
      services.Configure<JwtSettings>(Configuration.GetSection("JwtSettings"));
      JwtSettings settings = new JwtSettings();
      Configuration.Bind("JwtSettings", settings);
      services.AddMvc();
      } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
      if (env.IsDevelopment())
      {
      app.UseDeveloperExceptionPage();
      }
      app.UseMvc();
      }
      }
      }
    • 配置文件热更新
        <ItemGroup>
      <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3"/>
      <DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0"/>
      </ItemGroup>
    • 框架设计:Configuration

.net core 学习小结之 配置介绍(config)以及热更新的更多相关文章

  1. 我发起了一个 .Net Core 平台上的 开源项目 ShadowDomain 用于 热更新

    大家好,  我发起了一个 .Net Core 平台上的 开源项目 ShadowDomain  用于 热更新 . 简单的说, 原理就是 类似 Asp.net 那样 让 当前 WebApp 运行在一个 A ...

  2. .NET CORE学习笔记系列 开篇介绍

    ASP.NET Core学习和使用了一段时间了,好记性不如烂笔头,通过查阅官网学习文档和一些大神们的博客总结一下.主要路线先总结一下ASP.NET Core的基础知识,然后是ASP.NET Core  ...

  3. .net core 学习小结之环境配置篇

    安装IIs对 netcore 的支持 https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/aspnet-core-mod ...

  4. SpringCloud学习系列之五-----配置中心(Config)和消息总线(Bus)完美使用版

    前言 在上篇中介绍了SpringCloud Config的使用,本篇则介绍基于SpringCloud(基于SpringBoot2.x,.SpringCloud Finchley版)中的分布式配置中心( ...

  5. SpringCloud学习系列之四-----配置中心(Config)使用详解

    前言 本篇主要介绍的是SpringCloud中的分布式配置中心(SpringCloud Config)的相关使用教程. SpringCloud Config Config 介绍 Spring Clou ...

  6. SpringCloud全家桶学习之分布式配置中心----Config(七)

    一.概述 (1)背景 微服务意味着将单体应用中的业务拆分成一个个子服务,每个服务的粒度相对较小,因此系统中出现大量的服务.由于每个服务都需要配置必要的配置信息才能运行,所以一套集中式的.动态的配置管理 ...

  7. nopcommerce 4.1 core 学习 增加商城配置属性

    需求:  原本是想用nop 来做国际版的商城,可以像亚马逊那样 国内外通用,  专门增加一个跨进元素属性. 学习里面的一些架构思想.  国内的行情还是 像himall  会比较实用. 这是在商城的综合 ...

  8. Asp.net core 学习笔记 ( Configuration 配置 )

    参考 : https://cnblogs.com/nianming/p/7083964.html 配置写在 appsettings.json 里头 比如 { "object": { ...

  9. .net core 学习小结之 PostMan报415

    首先415的官方解释是:对于当前请求的方法和所请求的资源,请求中提交的实体并不是服务器中所支持的格式,因此请求被拒绝. 也就是说我所准备的数据格式并不是后台代码使用的数据格式 后台代码如下 using ...

随机推荐

  1. 【洛谷P2894】Hotel 线段树+二分查询

    题目大意:给定一个长度为 N 的序列,每个点有两种状态 1/0,表示占有和空闲,现支持 first-fit 查询是否有一段连续的长度为 X 的空闲子序列和区间赋值操作. 题解:get到了线段树新技能. ...

  2. 【POJ2486】Apple Tree

    题目大意:给定一棵 N 个节点的有根树,点有点权,边权均为1.现允许从根节点出发走 K 步,求可以经过的点权之和最大是多少. 题解:可以将点权看作是价值,将可以走的步数看作是重量,则转化成了一个树上背 ...

  3. Python之网路编程之死锁,递归锁,信号量,Event事件,线程Queue

    一.死锁现象与递归锁 进程也是有死锁的 所谓死锁: 是指两个或两个以上的进程或线程在执行过程中,因争夺资源而造成的一种互相等待的现象,若无外力作用, 它们都将无法推进下去.此时称系统处于死锁状态或系统 ...

  4. 判断request中是否有文件

    ServletFileUpload.isMultipartContent(request)

  5. HDU-2389-Rain on your Parade (最大匹配,kopcroft-karp)

    链接: https://vjudge.net/problem/HDU-2389 题意: You're giving a party in the garden of your villa by the ...

  6. ClustrixDB安装配置

    前提条件 在安装ClustrixDB之前,需要: ClustrixDB安装程序和许可证密钥. 运行CentOS或RHEL 7.4的服务器(本地或云中). 具有root或sudo特权来安装Clustri ...

  7. python 使用嵌套函数报local variable xxx referenced before assignment或者 local variable XXX defined in enclosing scope

    情况一: a 直接引用外部的,正常运行 def toplevel(): a = 5 def nested(): print(a + 2) # theres no local variable a so ...

  8. C2MIF软件使用说明

    1.右击---管理员身份运行 2.打开文件txt---搞定!

  9. luogu P1141 01迷宫 x

    P1141 01迷宫 题目描述 有一个仅由数字0与1组成的n×n格迷宫.若你位于一格0上,那么你可以移动到相邻4格中的某一格1上,同样若你位于一格1上,那么你可以移动到相邻4格中的某一格0上. 你的任 ...

  10. c++ 初学者 慢慢成长中

    C++书籍推荐 从上往下 Essential C++ C++ Primer 中文版 Effeetive C++ More Effeetive C++ C++ 标准程序库 深度探索c++对象模型 C11