Net Core获取配置文件appsettings.json

参考的appsettings.json

Net Core获取配置文件appsettings.json
{
  "ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.IdentityDb;User Id=sa;Password=Pass@word;",
  "IsClusterEnv": "False",
  "MvcClient": "http://localhost:5100",
  "SpaClient": "http://localhost:5104",
  "XamarinCallback": "http://localhost:5105/xamarincallback",
  "UseCustomizationData": false,
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Trace",
      "System": "Information",
      "Microsoft": "Information"
    }
  },
  "ApplicationInsights": {
    "InstrumentationKey": ""
  },
  "UseVault": false,
  "Vault": {
    "Name": "eshop",
    "ClientId": "your-clien-id",
    "ClientSecret": "your-client-secret"
  }
}
View Code

获取方式

1. Configuration["ConnectionString"]

2. Configuration.GetValue<string>("IsClusterEnv")

3. Configuration["Vault:Name"] //此方法未找到实例

4. Configuration.GetSection("Logging")

5. services.Configure<AppSettings>(Configuration);//实体类如下

    publicclassAppSettings

    {

        publicstring MvcClient { get; set; }

        publicbool UseCustomizationData { get; set; }

 

    }

Configuration提供的几种封装方式

Net Core获取配置文件appsettings.json

 

Net Core获取配置文件appsettings.json

上一篇:Vulkan(1)用apispec生成Vulkan库


下一篇:【Android开发】Android工程打压缩包技巧