configuring file for DLLs

你。 提交于 2019-12-12 11:34:25

问题


We are having application which load our custom DLLs (these DLLs are implementing some interface) on runtime from the root of the application and execute a method through reflection.

If custom DLL have to read some value from config files then we have to copy these config settings into app.config file of the main application.

Is there any way where each custom DLL will have own configuring file named .config and read its configuration settings from this files itself.


回答1:


If you're on .NET 2.0 or higher, you can manually tell the Configuration system to load the settings from any config file you want.

ExeConfigurationFileMap exeMap = new ExeConfigurationFileMap();
exeMap.ExeConfigFilename = "C:\Application\Default.config";

Configuration exeConfig = ConfigurationManager.OpenMappedExeConfiguration(exeMap, ConfigurationUserLevel.None);

Now you have your custom "Config" object and you can party on it! :-) Load a whole section by calling exeConfig.GetSection() or whatever you like.

Also check out this excellent three-part series on .NET 2.0 configuration system on CodeProject - highly recommended!

  • Unraveling the mysteries of .NET 2.0 configuration
  • Decoding the mysteries of .NET 2.0 configuration
  • Cracking the mysteries of .NET 2.0 configuration

Marc




回答2:


Load your DLL into a new AppDomain and set the AppDomainSetup.ConfigurationFile. This will let you create a separate config file for each custom DLL.




回答3:


I was certain there is a way to do this in the framework, just can't remember off the top of my head. What you're looking for is Per-Assembly configuration files, I remember reading an article about this Per Assembly Configuration Files



来源:https://stackoverflow.com/questions/743866/configuring-file-for-dlls

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!