I have a class that needs to get some settings from the application configuration file and that is used in a console based app and a web app.
Other than catching an exception how can I determine whether to use:
ServiceModelSectionGroup serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));
or
ServiceModelSectionGroup serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(WebConfigurationManager.OpenWebConfiguration("~"));
I’ve poked around and it seems you cannot do what you wish because the web model is different from the application model. Somewhat surprising that they don’t offer the usual case for this.
I’d add a
Configurationparameter to your class’s constructor and inject the dependency from the calling code.