Core读取配置

Core 获取配置文件

 

public class UploadService
{

//实例化配置节点
private readonly IConfiguration configuration;
public UploadService(IConfiguration configuration)
{
this.configuration = configuration;
}}

//获取配置文件值

var    connStr = configuration.GetSection("ConnectionStrings")["AA"];

}

 

appseting.json:

 

{
"Counts": {
"IGBT": 7,
"IGCT": 5
},
"ConnectionStrings": {
"PP": "TTTTT",
"AA": "TTTTT",
"BB": "TTTTT",
"FactoryCodes": "111,222,333,444,555,666,777",
"TraceTest": "TTTTT",
"TTke": "sTTTTT"

}
}

 

 

var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json").Build();
var workflowFilterAll = configuration["AuthCheck"];

 

var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json").Build();
var workflowFilterAll = configuration["workflowFilterAll"];

{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"AuthCheck": "False",
"ConnectionStrings": {
"SQLServerConnString": "SATAWTEWA",
"RedisConnectionString": "TTTTTTT"
},
"KPIItemConfig": {
"Step1BaseTime": 240,
"Step2BaseTime": 240,
"Step3BaseTime": 120,
"Step4BaseTime": 30,
"Step1Weight": 25,
"Step2Weight": 25,
"Step3Weight": 25,
"Step4Weight": 25,
"BaseScore": 80,
"ExtendTime": 10,
"ExtendScore": 8
},
"KPIYearsConfig": {
"ResponseRateWeight": 25,
"AbnormalTimesWeight": 25,
"GreatAbnormalTimesWeight": 25,
"CloseRateWeight": 25,
"AbnormalBaseCount": 50,
"AbnormalScoreReduction": 5,
"GreatAbnormalBaseCount": 0,
"GreatAbnormalScoreReduction": 50
},
"workflowFilterAll": "AAA",

"workflowFilter": "BBB",
"workflowId": "CCC",
"OAAutoLogin": "DDD",
"HostIpAddr": "CCC",
"mainTableName": "formtable_",
"appId": "1EEE",

"BelongCampus": "ZT"

}

posted @ 2024-01-22 16:50  似曾相识燕归来  阅读(3)  评论(0编辑  收藏  举报