Duncan
Duncan

Reputation: 21

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.

Upvotes: 2

Views: 413

Answers (1)

pathfinder666
pathfinder666

Reputation: 189

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.

Upvotes: 2

Related Questions