5

I am trying to understand plugin-architecture. Specifically the one used in the implmentation of Windows Live Writer. I am referring to the style where you can configure/enable/disable/add/remove additional functionality just by adding/removing DLL's(+ config).

I hope to see something similar for a web-based application. Can anyone please point me to the right direction?

Thanks in advance.

-SK

Sash
  • 3,525
  • 3
  • 19
  • 17

4 Answers4

3

Have look at this article. In a nutshell you need to do the following at a high level.

  1. Define an interface that the plugins must implement
  2. Create a sub-directory with specific permissions for the plug-in dlls to live in
  3. Define a configuration section or file that specifies the type to dynamically load from the plugin dll.
  4. Load dll's from the plugin configuration & directory into a secured sandbox using an AppDomain

I hope this helps.

James
  • 12,636
  • 12
  • 67
  • 104
1

Your question was tagged with ASP.NET, but I didn't see any ASP.NET specific stuff in your question. Pluggable ASP.NET is possible, but hard using System.AddIn, aka MAF. I managed to create a secure web-site plug proof of concept in in about 4 days.

http://suburbandestiny.com/Tech/?p=585

http://suburbandestiny.com/Tech/?p=588

The cool thing was finally being able to run an Add-In dll in Minimum Trust, while the host app ran in full or medium trust.

I finally concluded that System.AddIn was created to solve the AddIn challenges faced by Microsoft Office, not the challenges of creating an AddIn for a web.app.

MEF is supposed to be the new shiny thing to do add-in type patterns, but I don't have any experience with it. MEF was meant to be a general solution and not just to solve problems on the MS Office team, so it is somewhat more promising.

MatthewMartin
  • 32,326
  • 33
  • 105
  • 164
0

Basically you would need to use the AssemblyLoader to load an assembly at runtime from a specified directory, then create an instance and invoke it.

    Assembly assembly = Assembly.LoadFrom("myAssembly.dll");
    Type type = assembly.GetType("theType");
    object myInstance = Activator.CreateInstance(type);

It works best if all your plugins implement an interface that exposes a certain method...like Load(). Then you can do:

myInstance.Load()

Provided you cast myInstance to your interface.

Chris Kooken
  • 32,730
  • 15
  • 85
  • 123
  • 3
    The problem with this is that it is that it creates a security risk. It's better to load into a sandbox using an `AppDomain`. – James Dec 13 '10 at 21:24
0

The auto-detection of a plugin, simply by adding a DLL(s), is encapsulated in the System.Addin namespace. Each time you restart the program, it will add/remove the given plugins. As you can see, what it will not do is add/remove a plugin while the program is still running. If you want that capability, then you will need to augment the System.Addin code by adding your own file-event mechanism that informs you that a DLL was added or removed. Of course if you want to remove a DLL for something that is alreay executing, that DLL must not have a file-lock on it. To achieve that, you would have each DLL be executed with ShadowCopy turned on.

Brent Arias
  • 29,277
  • 40
  • 133
  • 234