Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plugin architecture with GUI

Tags:

I'm developing an application that makes heavy use of plugins. The app is in C# and I'm thinking about building the configuration GUI in WPF. I got the plugin architecture down in terms of how to manage the actual plugins themselves. However, each plugin has its own configuration, and that's where I'm looking for help.

The plugin architecture is simple -- there's an interface that plugins implement and I just load all the plugins inside a directory. However, where do the plugins get their configuration from? I'd like to have some generic way of handling this, so that each plugin isn't responsible for reading its own configuration file. Also, I'd like the GUI to expand with each plugin -- that is, each plugin installed should add a tab to the GUI with the specific configuration options for that plugin. Then upon save, the configuration file(s) would be saved.

What's my best way of going about this?

like image 290
noah Avatar asked Nov 18 '09 15:11

noah


People also ask

What is a plugin architecture?

A plug-in is a bundle that adds functionality to an application, called the host application, through some well-defined architecture for extensibility. This allows third-party developers to add functionality to an application without having access to the source code.

What is a plugin framework?

The plugin framework is a NuGet package that allows you to customise and extend a .NET application. Plugins are loaded at runtime from a catalogue which can be a local source or via NuGet. Supports all the current . NET Core based applications, ranging from Blazor to ASP.NET Core and to Console, WPF and Windows Forms.

What is the benefit of a plugin architecture?

The plug-in architecture offers the following advantages. Due to the separation of the customization code changes from default code, plug-ins can be used to extend functionality of MicroStrategy Web without the need to recompile or to add new functionality to MicroStrategy Web without requiring access to source code.


1 Answers

Define an interface for configurable plugins:

public interface IConfigurable {   public void LoadConfig(string configFile);    public void ShowConfig();    // Form or whatever, allows you to integrate it into another control   public Form GetConfigWindow(); } 

The just invoke the IConfigurable interface for configurable plugins.

If you want you can make the interface work the other way, making the main application provide a container (a frame or a dock for example) to the plugin for it too feel, but I would recommend the other way around.

public interface IConfigurable {   void LoadConfig(string configFile);    void ShowConfig(DockPanel configurationPanel); } 

Finally you can do it the hard way, by defining exactly what the plugin can offer as configuration option.

public interface IMainConfigInterop {   void AddConfigurationCheckBox(ConfigurationText text);   void AddConfigurationRadioButton(ConfigurationText text);   void AddConfigurationSpinEdit(Confguration text, int minValue, int maxValue); }  public interface IConfigurable {   void LoadConfig(string configFile);    void PrepareConfigWindow(IMainConfigInterop configInterop); } 

of course this option is the more restrictive and more secure one, since you can limit perfectly how the plugin is able to interact with the configuration window.

like image 81
Jorge Córdoba Avatar answered Nov 22 '22 06:11

Jorge Córdoba