English 中文(简体)
Setting application hooks - C#/ASP.NET
原标题:

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.

最佳回答

Given Alex s answer, this should be useful:

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

问题回答

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.

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.

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??

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





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签