tags:

views:

285

answers:

3

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.

+2  A: 

Let the main application get the plugin directory from the application settings and push it into the plugin system.

EricSchaefer
+1  A: 

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.

Frode Lillerud
That's exactly what I was saying...
EricSchaefer
+1  A: 

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.

Bryan Watts