I am trying to access appsetting.json
file from a class library. So far the solution that I found is to create a configuration class implementing interface IConfiguration
from Microsoft.Extensions.Configuration
and add the json file to class and read from the same.
var configuration = new Configuration();
configuration.AddJsonFile("appsetting.json");
var connectionString= configuration.Get("connectionString");
This seems to be bad option as we have to add the json file each time we have to access the appsetting configuration. Dont we have any alternative like ConfigurationManager
in ASP.NET.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…