Let me start out by saying that I'm aware that the way a class library is supposed to get its configuration is from the referencing project's configuration. In my case, the referencing project is an MVC web application.
Whilst this usually makes sense, I don't think it does when your class library is there just to provide access to a web service. Visual Studio has a feature when you right-click on the service reference to "Update Service Reference". This will update the app.config
file in the class library, not the configuration file in the referencing project. Not very useful if the app.config
file is just going to be ignored.
Of course, you can keep copying the new versions of the app.config
file over to (in this instance) your web.config
file in a different project, but it's a pain, and you have to keep remembering to do it. Whatsmore, I think it's semantically better to keep the config settings in the web service project. If that web service changed URLs, I'd want all things referencing the project to get the new URL. If something referencing the class library wanted to use a different URL, its configuration could override the class library's, but I'd still like the class library to have a default bunch of settings. I wouldn't want to have to change each referencing project's configuration.
With all that in mind, is there a way to force/hack/whatever .NET into using a configuration in a class library for WCF endpoints, etc., instead of looking at the values in the referencing project's configuration?