Reputation: 48736
I have a data access layer that is compiled as a class library and compiles to a dll. Historically, the dll provided data access to my database for my web application. It works just fine, but what its doing is it is pulling my connection string from the web.config. This is fine too, but now I want to use this data dll in a Windows Form application. Is there a way for the DLL to know if its running inside a web application or winform application and to appropriately pull the connection string from either the web.config or app.config file?
Upvotes: 1
Views: 165
Reputation: 28540
As I put in my comment, a class library will use the configuration file of the application that is referencing it. It doesn't matter if it's WinForms or a Web App. As long as there's a config file, the library will be able to access it/use it.
That's one of the big advantages of using libraries for reusable code.
The caveat to this is to make sure that the correct information is in the config files (app or web) :)
Upvotes: 3
Reputation: 58665
Actually, from a decoupling perspective, the best approach would be having the application which is using the DLL provide the connection string to the library.
Upvotes: 1