public class TraceUploadService
{
//实例化配置节点
private readonly IConfiguration configuration;
public TraceUploadService(IConfiguration configuration)
{
this.configuration = configuration;
}}
//获取配置文件值
var connStr = configuration.GetSection("ConnectionStrings")["AC1"];//AC1
}
appseting.json:
{
"Counts": {
"BG": 7,
"CG": 5
},
"ConnectionStrings": {
"PG": "PORT=5432;DATABASE=t_insp_data;HOST=10.80.65.48;PASSWORD=biel.pos.123456;USER ID=postgres",
"connStr": "server=192.168.26.220;database=TrackTraceac2;user=biel;password=BIEL03010666",
"AC1": "server=192.168.26.223;database=TrackTraceac1;user=biel;password=BIEL03010666",
"AC2": "server=192.168.26.220;database=TrackTraceac2;user=biel;password=BIEL03010666",
"AC3": "server=192.168.26.222;database=TrackTraceac3;user=biel;password=BIEL03010666",
"FactoryCodes": "GR7,GR9,FX9,FXC,FXD,FXG,G08",
"TraceTest": "server=192.168.26.173;database=Trace_DB_Test;user=biel;password=BIEL03010666",
"Trace": "server=192.168.26.173;database=Trace_DB;user=biel;password=BIEL03010666"
}
}