构造函数注入 IConfiguration
private readonly IConfiguration _configuration;
public XXXController( IConfiguration configuration)
{
_configuration= configuration;
}
使用
_configuration.GetValue<string>("MYConfig:Computer");
appsetting.json
"MYConfig": {
"Computer": "127.0.0.1",
"UserName": "demo",
"Password": "demo"
}