I have class two ViewModels
//both IViewModel1 and IViewModel2 inherit from IViewModel
public class ViewModel1 : IViewModel1
{}
//and
public class ViewModel2 : IViewModel2
{}
and the view :
public partial class View : UserControl
{
View(IViewModel)
{}
}
How can I do to inject one of the ViewModels into the View using Unity container ?
Edit : My issue is on having choice to inject one of the view models from the constructor.
If you use Unity to resolve your view and the IViewModel is part of the signature of the constructor then Unity will resolve it for you (provided you have already registered it, for example in the loading of a module):
Keep in mind that Unity is greedy – it will try to resolve the biggest constructor it can so if you want to select a particular constructor for it to use then you will need to use ParameterOverrides.