how to implement Mutliple Class Inherit from Same Interface, How does Prism Resolve by particular type

Jan 31, 2014 at 2:40 AM
How to implement dependency injection, if in case if I have single interface with Multiple classes inheriting from it. How can i resolve them by name ?. My View and ViewModel is in Different Project. How can i resolve particular type based on named parameter in Prism.

Our scenario is we have Online and Offline. Both Online and Offline class implement same Interface Contract. Depending Application state , i need to use either Online Service COncrete Class or Offline Concrete Class. I have created Factory Class to return Interface Type Object. But how to decide which object to resolve, since we have 2 class with same Interfaces registered to Container. I dont see some thing like [Dependency("XYZ")] in prism
Feb 4, 2014 at 5:50 PM

Depending on the container you are using you might be able to specify the object you want to obtain from the container using an id or name in a constructor or a property. However, as Prism does not support any DI container as out of the box (it can be used without a container) it does not provide guidance about dependency injection. To find how to do this you will need to check the documentation of the container you are using.

If you are using Unity in your application, like the Adventure Works Shopper does, you can find its documentation in the following link:
If for your scenario you need more control on what parts you will obtain from the container (for example, you need to obtain an instance of the interface you are mentioning after the view model has been created) you could inject the container itself and then request the corresponding parts to it programatically. You can obtain Unity's container through the IUnityContainer interface.

I hope this helps,

Damian Cherubini