I have a lot of code that uses a ViewModelLocator to set the datacontext on views.
I'm currently using a simple service locator (Simple Injector / CuttingEdge.ServiceLocation) so that the ViewModelLocator with a parameterless constructor can be instantiated from XAML in Window or UserControl.Resources and then used to set the DataContext.
I'm in the process of changing to use Ninject and thought I'd be able to continue to use the ViewModelLocator in the same way. However, I've now found that Ninject doesn't directly support service location (and it appears that service location is a concept that has fallen out of favor).
I'd like to continue to specify a views viewmodel from XAML (using a ViewModelLocator derived class) but I can't find a tidy was of doing this with Ninject.
I can't find any way of doing this. How are other developers doing this without a IoC container that supports IServiceLocator (or similar)?
Notes:
- the only MVVM library I'm using is Josh Smith's MvvmFoundation.Wpf.
- I've seen the blog post Use Ninject to decouple discovery of your viewmodel's in mvvmlight's viewmodellocator but this method doesn't seem right.