I'm trying to use Microsoft.Practices.ServiceLocation.ServiceLocator and MEF. Interface IServiceLocator defines method GetInstance with two parameters. First parameter is serviceType and second paremeter is key.
I have two classes which implement interface IMyInterface and they have Export attribute:[Export(typeof(IMyInterface)), PartCreationPolicy(CreationPolicy.Shared)]
public class Class1 : IMyInterface
{}
[Export(typeof(IMyInterface)), PartCreationPolicy(CreationPolicy.Shared)]
public class Class2: IMyInterface
{}
I want to get instance of Class1 via Prism ServiceLocator GetInstance method:
ServiceLocator.Current.GetInstance(typeof(IMyInterface),"Key");
But I have no idea how and where should be "key" defined. I tried to define key in export attribute:
[Export("Key1",typeof(IMyInterface)), PartCreationPolicy(CreationPolicy.Shared)]
public class Class1 : IMyInterface
{}
[Export("Key2",typeof(IMyInterface)), PartCreationPolicy(CreationPolicy.Shared)]
public class Class2: IMyInterface
{}
When I call method GetInstance with key parameter
ServiceLocator.Current.GetInstance(typeof(IMyInterface),"Key1");
I get Microsoft.Practices.ServiceLocation.ActivationException (Activation error occured while trying to get instance of type IMyInterface, key "Key1"). Does anybody know how can be the export key defined? Thanks