tags:

views:

249

answers:

5

Many popular applications such as Wordpress, WHMCS and the majority of PHP forums allow plugins to hook into core application events (such as registration, logging in, create post etc.) by simply specifying a function with a particular name.

I understand that these applications are not pre compiled, but is it possible to do something of the sort with C#? I've looked into event handlers, but it seems that you can only accomplish this if the plugin has the ability to instantiate the class that we want to hook into (or at least thats what searching has lead me to believe)

Ideally, these hooks would be into business layer class events/methods and can be hooked into by multiple objects, so it would function in either WinForms or ASP.NET MVC.

+1  A: 

There is an AddIn framework shipping with .NET 3.5. The framework provides very powerful mechanisms to expose interfaces by a host application and to manage, dynamically load-unload addins etc.

Alex
A: 

Why the core concept that comes up to my mind first, is Dependency Injection? I haven't ever played with a plug-in system in any app of mine. Does DI could help anyhow with that??

Aggelos Mpimpoudis
Is this an answer ?
Yassir
If someone approves technologically, maybe it is!
Aggelos Mpimpoudis
+2  A: 

If you design your application for extensibility, this is easy. The Managed Extensibility Framework is designed for exactly this sort of scenario, and makes it very easy.

It will be included as part of the core framework in .NET 4, but is downloadable now for use in 3.5.

Reed Copsey
Maybe also useful: MEF vs. System.AddInhttp://social.msdn.microsoft.com/forums/en-US/MEFramework/thread/cf6b7cbc-1123-4b32-9810-c235d9606b66
Alex
+2  A: 

Given Alex's answer, this should be useful:

System.AddIn Tools and Samples
http://clraddins.codeplex.com/

Robert Harvey
A: 

Specifics on our senerio would be helpful, but generally, You may want to explore the provider psttern.

There are 3 components: - An abstraction of a piece of functionality, (Interface/baseClass) - A Factory method that looks to config to determine what type of Class to create - [your] Custom Class which extends/implements the abstraction. for example, a Membership provider class that hits a custom dasta source for user info.

This is very useful when switching out logic. If you want to create an app with swappble UI components, it is another story.

There is support for this in ASP.NET, starting with 2.0. More info on the provider: http://msdn.microsoft.com/en-us/library/ms972319.aspx

brian chandley
Interesting Brian, just out of curiosity, how would you create swappable UI components ?
ram
Ram, Honestly, not sure. I am not aware of a well defined/standard way to apprach this. I do not think it would be a simple matter in the context of ASP.NET.
brian chandley