views:

75

answers:

2

I’m writing an ASP.NET MVC 2 application where developers could extend it with plugins. I’ve started to consider how create a plugin system. (e.g. like Joomla’s)

I have some doubts about how to do this. I have searched over the net and I found that there are two potential solutions.

  • using interfaces or abstract classes to implement methods and a plugin-structure, load the assembly, cast the object to the interface and call the methods that the plugins should have when i need to hook the system.

  • using C# events to load the assembly and raise the events where I need to hook the system. The plugin in the constructor will register the function with the event provided by my application.

What is the best solution? What performance considerations are there? What other approaches could there be?

+4  A: 

Rather than writing your own plugin system, you should probably consider the Managed Extensibility Framework (MEF) which is Microsoft's own plug-in framework.

Jon Skeet
i don't think MEF is really what i need... it's complex and i need only a plugin-based system that allow developers to write their own plugin, register it with the mainframe and the application do the rest... but i have doubts on what use, interfaces/abstract class or events
Stefano
MEF works pretty well for what I've been doing. Particularly using MEF to create modular ASP.NET MVC sites is what I set out to do. I blogged about it http://www.fidelitydesign.net/?p=130
Matthew Abbott
+1  A: 

Have a look at the Orchard project on Codeplex. The Microsoft developers have build a plugin mechanism similar to what you are describing. Its pretty complex stuff...

Clicktricity
Great project this Orchard! I will check it
Stefano