I recently had the opportunity to create a new prism-based application. I had been using the 6.3 version for quite a while, but saw the prism 7 had moved out of prerelease and wanted to give it a try. I created a new prism application using the Prism Template pack and all worked as expected out of the box. I updated the view model like typically do in 6.3 to pass in the Container so I could resolve some objects that at a later time would provide information to the view, in 6.3 I would do the following:
public MainWindowViewModel(IRegionManager aRegionManager,
IUnityContainer aUnityContainer) : base()
Now in 7.1.0.431, I tried to do that same thing, but updated the interfaces to account for the new IOC abstraction.
public MainWindowViewModel(IRegionManager aRegionManager,
IContainerProvider aContainerProvider,
IContainerRegistry aContainerRegistry) : base()
This generates an exception from the ViewModelLocator.AutoWireViewModel for the IContainerX parameters.
System.Exception {Unity.Exceptions.ResolutionFailedException}
{"Resolution of the dependency failed, type = 'Sample.ViewModels.MainWindowViewModel', name = '(none)'.\nException occurred while: while resolving.\nException is: InvalidOperationException - The current type, Prism.Ioc.IContainerProvider, is an interface and cannot be constructed. Are you missing a type
That acts like I am missing a reference, but I that type is being passed into the RegisterTypes call of the application, so all references should be found. Am I doing something wrong for the new 7.X release?
EDIT: Per @mnistic
Here is the code from the template pack provided App.xaml.cs where the IContainerRegistry is passed in.
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
//containerRegistry is a valid instance here
}
Update:
Digging in a little more, the IContainerRegistry that was passed into RegisterTypes lists all of the types/interfaces that are available at the time that method was called. It has an IUnityContainer instance registered. I selected Unity for the IOC when I created the project, but I assumed, maybe incorrectly, that the IContainerRegistry was hiding the clients from the actual implementation. If I update the ViewModel constructor to take in a object of IUnityContainer, it resolves properly.
public MainWindowViewModel(IRegionManager aRegionManager,
IUnityContainer aContainerProvider) : base()
Is this the desired behavior?