You can create a mapping class for your configuration, like this:
public class ConfigSettings
{
public string ConfigSetting1 { get; set; }
public string ConfigSetting2 { get; set; }
public string ConfigSetting3 { get; set; }
public SubConfigSettings1 SubConfigSettings1 { get; set; }
}
public class SubConfigSettings1
{
public string SubConfigSetting1 { get; set; }
public string SubConfigSetting2 { get; set; }
}
and fetch them using,
var setting = Configuration.Get<ConfigSettings>();
EDIT:
if you have this steeltoe config
{
"spring": {
"cloud": {
"config": {
"uri": "http://localhost:8888"
}
}
},
"Logging": {
"IncludeScopes": true,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
},
"Console": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
}
You can define the ConfigSettings class like this.
public class ConfigSettings
{
public Spring spring { get; set; }
public Logging Logging { get; set; }
}
public class Spring
{
public Cloud cloud { get; set; }
}
public class Cloud
{
public Config config { get; set; }
}
public class Config
{
public string uri { get; set; }
}
public class Logging
{
public bool IncludeScopes { get; set; }
public Loglevel LogLevel { get; set; }
public Console Console { get; set; }
}
public class Console
{
public Loglevel LogLevel { get; set; }
}
public class Loglevel
{
public string Default { get; set; }
public string System { get; set; }
public string Microsoft { get; set; }
}
and use like this.
services.Configure<ConfigSettings>(Configuration);
and use the following to access uri section, for example.
var settings = Configuration.Get<ConfigSettings>();
string springCloudConfigUri = settings.spring.cloud.config.uri;
here, the Configuration is IConfiguration