Location of Service Implementation

Topics: Prism v4 - Silverlight 4
Apr 13, 2011 at 7:52 PM

Pls help...
There are:

CommonClassLibrary (IMyService interface)
- ServiceImplementation ClassLibrary (MyService: IMyService) with 2 attributes applied:  [Export(typeof(IMyService))] and [PartCreationPolicy(CreationPolicy.Shared)]
- ModuleA using MyService (references to ServiceImplementation) :  [Import] public IMyService Service { get; set; }
- ModuleB using MyService (references to ServiceImplementation) :  [Import] public IMyService Service { get; set; }

Shell App loads ModuleA, and Service property initialized. Everything is cool.
Now Shell loads ModuleB, and I get exception... Changing  Service property to  List<IMyService> service with attribute ImportMany solves problem...
I understand that because ModuleB loaded there are more then 1 export of type IMyService...

Pls advice how to arrange solution, that each module has  [Import] public IMyService Service { get; set; }.   I belive  [PartCreationPolicy(CreationPolicy.Shared)] on service implementation should do this trick, but obviously not.....

Apr 14, 2011 at 2:24 PM


Based on my understanding of your scenario, one possible way to ensure your dependency is resolved correctly could be to directly specify imports through constructor parameters. By doing this you avoid any timing issues when resolving your imports as property imports. For example like this:

private readonly IMyService service;

public ModuleA(IMyService theService)
    service = theService;



If you continue experiencing this issue, it could be helpful if you could provide us with a repro sample of your solution, so that we can help you to identify the cause of your issue.


Miguel Bronzovic