views:

14

answers:

1

After creating settings for each dll, a .dd.config file is generated. If that dll would be part of an asp.net application, how to keep this configurations separate for each dll and don't merge them into web.config ?

A: 

Creating an App.config for a DLL is not a good practice. Configuration belongs to the running application. The class library dll is supposed only to provide services to the calling application.

HOWEVER

If you wrote the DLLs on your own, then you can make these DLL's code prefer their own independent .dll.config file rather than the global App.config/Web.config (in your ASP.NET case) using a trick.

This method allows you to open any executable file's .config file, but no one prevents you from calling it with "Mydll.dll" as argument, and has the same effect. But this works only if you can access these DLL's code.

A good practice is to use configuration sections, which are easy to maintain when merged inside a single configuration file.

djechelon
I've tried that. It doesn't work with asp.net since dlls are not executing from bin folder, instead asp.net would run a copy from a temp folder which it's address changes on every application restart. I wonder why dll.config is not popular when a dll have configurations which are not related to the using application. Consider a mailSender which stores the username/password of using account in it's dll.config
Xaqron
There can be a workaround to it. I don't currently remember exactly which methods can help you, but you can copy any file you want from any directory to the directory ASP.NET is executing. Try to search how to get the path ASP.NET copied the compiled web application in Temporary ASP.NET folder and there copy the .config files.
djechelon