简体   繁体   中英

Using application settings across assemblies

I'm writing an application that includes a plugin system in a different assembly.

The problem is that the plugin system needs to get application settings from the main app (like the directory to look for plugins).

How is this done, or am I going about this the wrong way?

Edit: I was encouraged to add some details about how the plugin system works. I haven't completely worked that out and I've only just begun implementing it, but I basically went by this article .

让主应用程序从应用程序设置中获取插件目录,并将其推送到插件系统中。

Perhaps you could insert the configuration as an argument when creating the plugin?

//Get the configuration for the current appDomain
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

//Create the plugin, and pass in the configuration
IPlugin myPlugin = new AlfaPlugin(config);

You'll probably need a reference to the System.Configuration assembly.

You can write a custom configuration section, which allows you to write objects representing an XML schema. Once established, you can simply ask for the current instance of that section.

You can do this by deriving from System.Configuration.ConfigurationSection and writing properties which represent attributes and sub-elements. For more information, see How to: Create Custom Configuration Sections Using ConfigurationSection .

The AppDomain in which the library is running is the current configuration scope. The System.Configuration namespace correlates all config files and presents a unified view.

To retrieve the current instance of a section, you can use ConfigurationManager.GetSection(...) .

Your plugin should accept an instance of this section instead of a general Configuration object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM