I have a ViewModel class that I want to resolve with a single ServiceLocator, but my viewModel requires a parameter for the constructor. The parameter type is one of the objects of my application (the Customer object), and not some implementation of the service. I know that for encoding the Unitycontainer itself I can pass this parameter:
_container.Resolve<CustomerDetailViewModel>(new ParameterOverrides {{"customer", customer}});
but if I do not have direct access to the container, I need to go through the ServiceLocator as follows:
(CustomerDetailViewModel)ServiceLocator.Current.GetInstance<CustomerDetailViewModel>();
However, using the second approach, I cannot pass any parameters to ServiceLocator. Can this be done? Is it "wrong" to get a container instance from ServiceLocator and then use it?
source
share