This project has moved and is read-only. For the latest updates, please go here.

Satisfy part on an Export using Metadata

Jun 17, 2010 at 1:37 PM


I have the following scenario in Silverlight 4:

I have a notifications service


    public interface INotificationsService : IObservable<ReceivedNotification>
        void IssueNotifications(IEnumerable<ClientIssuedNotification> notifications);

and and implementation of this service
    public class ClientNotificationService : INotificationsService
        IPlugin Plugin { getset; }

How can I say to MEF that the Plugin property of the ClientNotificationService must be provided by the importing class that imports the INotificationsService.

For example:

    public class Client
        IPlugin Current { getset; }

        INotificationService NotificationService;
How can I say that I want MEF to satisfy the ClientNotificationService.Plugin part with the exported IPlugin by the Client class.

Basically I want the NotificationService, to receive a Unique ID provided by the importing class, whenever it is created and composed to a new class,
or if there's and alternative method, like using meta data to do this I'd appreciate any insights. I've been struggling with this for a while.


Jun 18, 2010 at 10:48 AM
Hi, As I understand it, what you'd like is to create multiple Client objects and have all of these receive unique notification services, each with a link back to the Client instances via IPlugin. Although it isn't super elegant, the simplest method to achieve this is to have the INotificationsService expose a SetPlugin(IPlugin) method, that will be called by the Client when its notification service import is satisfied: public class Client { IPlugin Current { get; set; } [Import] INotificationService NotificationService { set { value.SetPlugin(Current); } } } There are other 'scoping' solutions but as far as I'm aware they will take a lot more work to implement. Someone may correct me here :) Cheers, Nick
Jun 21, 2010 at 7:32 AM

Thank you, for your answer, I was looking for a 'scoping' solution, but there doesn't seem to be an easy way to do it. I will research more on this subject too see how I can implement such a solution.