开发者

MEF Extension Events

I am a new developer to MEF (Managed Extensibility Framework) and have managed to get a sample application up and running, with several extensions. This is a nice framework to use.

What I am looking to do is to implement 开发者_运维知识库a standard event which is available to raise from each extension. For example, in my Host application i would have an EventHanlder

Extension_OnLog (string Message) //Perform some logging here.

And then each Extension would be able to raise this event, which is handled in the Host Application.

//Extension 1 RaiseEvent OnLog("This is some logging text")

I am not sure of the correct terminology of this. Could someone please point me in the right direction for implementing such an event model.


Something like this can work:

Create two interfaces:

IEventRaiser (which will contain function RaiseEvent)

IEvent1 (which will contain the actual event)

Create a module (Event1) which will implement both the intefaces and will export both the interfaces.

Your "extensions" can import IEventRaiser which will allow them to raise the event.

Host application will import IEvent1 which will allow it to "subscribe" to the event.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜