参考的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"
}
}
获取方式
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提供的几种封装方式