In the MVC 6 project, I have the following configuration file ...
{
"ServiceSettings" :
{
"Setting1" : "Value"
}
}
... and the next class ...
public class ServiceSettings
{
public Setting1
{
get;
set;
}
}
In the ConfigureServicesclass method , StartupI added the following line of code ...
services.Configure<ServiceSettings>(Configuration.GetConfigurationSection("ServiceSettings"));
If a value is needed Setting1, how to check it? I could argue that the instance is IOptions<ServiceSettings>actually used, but if the value is Setting1necessary for the service to work, I would like to catch it as soon as possible, and not further downstream. The old object ConfigurationSectionallows you to specify rules that throw exceptions when configuration data was read if something was invalid.
source
share