views:

123

answers:

1

I have several class libraries within my MVC application which each have a Settings file with its own configuration file. With each configuration file being App.config, how are these aggregated into one configuration file? Should the settings be placed in web.config? Suggested best practice?

+1  A: 

When you build each class library you'll notice that the app.config file is copied to the bin\output folder with a name like "myclasslibrary.dll.config". This means that each DLL will have it's own config file each with a unique name. You can just include the *.dll.config files in your website's bin folder along with the DLLs and your settings will be picked up.

You can also combine settings from a library's app.config into the web.config file by adding new <section> declarations inside <configSections>.
This MSDN walkthrough has an example: http://msdn.microsoft.com/en-us/library/ms246220%28VS.80%29.aspx
Then you wont need separate config files.

AUSteve
Thank you AUSteve, I suspected the first and hoped for something like the second approach.
ccook
Either method works fine and the web app doesn't care or need recompilation if you change. If you're early in the dev cycle I suggest leaving the separate config files as they are. Once the code (and the number/names of settings) stabilise you could combine them into the web.config for ease of deployment/maintenance.
AUSteve
Excellent, thanks again!
ccook