I have created Sample class to the Key Values from application (appSettings.json). for that i have initialise the Configuration instance at Constructor level. Later on consumed same instance to get the Key Value.
Sample Code is Below
Calling from application
string Conn = ConfigurationExtension.GetConfigKeyValue("ConnectionStrings:DBConnection").ToString();
Base Code
public class ConfigurationExtension
{
IConfiguration configuration;
public ConfigurationExtension()
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appSettings.json");
configuration = builder.Build();
}
/// <summary>
/// Get appSettings json key value ex Key: "ConnectionStrings:DBConnection"
/// </summary>
/// <param name="Key"></param>
/// <returns></returns>
public static string GetConfigKeyValue(string Key) {
ConfigurationExtension obj = new ConfigurationExtension();
string con = obj.configuration[Key].ToString();
return con;
}
}