Implementing Plugin Architecture - Dynamic DLL loading

NLV picture NLV · May 25, 2011 · Viewed 16.5k times · Source

I've an application which is basically a designer with preloaded controls where you can design your pages using the controls.

I'm planning to release more and more controls in the future. I don't want to release a new build for newly added controls as it has its disadvantages. So I was thinking of addon/plugin kind of architecture where I just release the addon/plugin separately which they can install and get the controls inside the designer.

Right now I'm using xml files as addons to specify the controls, its behaviors, its styles etc. Each xml (addon) represents a single control. But I'm finding it very difficult to implement this since I've to write a generic parser to read all the plugins.

Instead, can I release a dll for each addon which gives me more control to write code to define the behavior/look of the control and dynamically load it through the main engine? If so how can I check for dlls and load it dynamically in my application?

Answer

Daren Thomas picture Daren Thomas · May 25, 2011

You might want to look at the Managed Extensibility Framework. This will probably solve most of your issues and more, but will require learning some new tech...

You should also definitely look into the System.Addin Namespace as mathieu suggests!

If you want to go with your own route, I suggest the following approach:

  • an interface for addons in your main application
  • implement that interface in addon dlls
  • load the dlls at runtime with Assembly.Load
    • you might want to look into loading the addon assemblies into a separate AppDomain