Trying to learn Visual Studio 2015 MVC and looking for some advice on how to retrieve multiple config values from config.json.
Currently I have the following:
public IEnumerable<WeatherConfigValues> WeatherAppSetting()
{
var con = new Configuration();
con.AddJsonFile("Config.json");
var weatherConfigSettings0 = con.Get("AppSettings:WeatherKey");
var weatherConfigSettings1 = con.Get("AppSettings:Weather_FeedKey");
var weatherConfigSettings = new List<WeatherConfigValues>
{
new WeatherConfigValues {WeatherKey = weatherConfigSettings0},
new WeatherConfigValues {WeatherFeedKey = weatherConfigSettings1}
};
return weatherConfigSettings.ToList();
}
Just ignore the names as I'm just trying to get code to work.
The above code does work and I can get the values in another class Library with the following:
var weatherSettings = new CustomConfigurationSettings();
var getData = weatherSettings.WeatherAppSetting().ToList();
var test1 = getData[0].WeatherKey;
var test2 = getData[1].WeatherFeedKey;
I have been looking at numerous websites such as http://blog.jsinh.in/asp-net-5-configuration-microsoft-framework-configurationmodel/#.VVYkyPlVhBd and http://whereslou.com/2014/05/23/asp-net-vnext-moving-parts-iconfiguration/ but I'm not sure if I'm doing it the correct way, I tried GetSubKeys but that just returns null values.
So my question is, is this the correct way, or is there a correct way.