Using app.config with a class library

后端 未结 9 1351
忘掉有多难
忘掉有多难 2020-11-27 06:47

Frequently I need to create a .Net class library that requires an app.config for things such as database connection strings. However, these settings must be in the calling a

9条回答
  •  旧时难觅i
    2020-11-27 07:07

    Here is an alternative.

    Instead of attempting to find ways to "merge" your app.configs, or even placing configuration items in your DLL (and trying to work around what is "by design") in the first place, try this:

    Create your DLL, but where you need a Config Item, create a public Property. When you instantiate the class in the DLL, you populate these properties with config items from the owning application.

    Now the configuration is managed at the owner level, and the DLL is portable, as you have to pass what you need to it at run time.

    No more DLL.config!

提交回复
热议问题