I am trying to create a module with PRISM and right now I set the DataContext inside the View which means I can only use a Parameterless constructor, but that means I cant use dependency injection (I use Unity) in the constructor which I would like
If it is possible I would like neither the view or the vm to know each other and want to use something like
private void RegisterServices()
{
var employeeViewModel = new EmployeeViewModel();
_container.RegisterType<IEmployeeViewModel, EmployeeViewModel>();
_container.RegisterType<EmployeeView>();
EmployeeView.Datacontext = employeeViewModel;
}
Which I would register in the EmployeeModule
Is this possible or should I use code behind?
You may pass the interface of
ViewModelto theViewin the constructor. This way,Viewonly knows the interface ofViewModelandViewModelknows nothing about theView.Ex.
Refer to this blog post for multiple approaches of MVVM instantiation.