views:

2037

answers:

4

In my project I have functionality that is being used as a web application and as a console application (to be started from the task scheduler). To do that I put the common code in a DLL that is being used by both the web application and the console application. This works fine.

However, the console and web applications now have an App.config and Web.config that are mostly the same. Is it possible to put this configuration in the DLL as well and make it available to both applications?

+1  A: 

I'd suggest that you move the configuration loading to the dll rather than the entire configuration, and then call it from the different apps. This is so that:

  1. You don't need to recompile to change config data (always useful)
  2. If you need to split the config again in the future, this will already be possible with the dll.
workmad3
+4  A: 

Yes, you can and should put the common configuration settings in the config file for your DLL. Just add an app.config file to the DLL project, and make sure you read the configuration settings from inside the DLL. When deployed, your config file needs to have the name "MyDLL.dll.config" (assuming your DLL is named "MyDLL.dll") and be in the same folder as the DLL.

MusiGenesis
Whats if it's in the GAC?
Ryu
A: 

you could put the common configuration under the windows registry, accessible wherever you like

Lorenzo Boccaccia
Kind of tough to deploy to a new machine.
MusiGenesis
only if he deploys by hand. also, the first time default values could be inserted by the first one reading them
Lorenzo Boccaccia
+1  A: 

Assuming you are using .Net, you can set up a .settings file to store your configuration data - the data contained there will be stored as default values for those config entries so even if there is no app.config file, your application will run with those defaults.

I'm not saying that's a good thing... 8)

So, if you build a project that references your DLL, you would add the same .settings file to that project and those settings would appear in the app.config file for the app and the DLL would be able to read those values. IF those values aren't in the app.config, the dll will fall back on the defaults.

Most people will think that's a bad thing and I tend to agree but there you are.

ScottCher