title: MVVM ViewModelLocator with Ninject
body: <p>I have a lot of code that uses a ViewModelLocator to set the datacontext on views.</p>
  
  <p>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.</p>
  
  <p>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 (<a href="http://blog.ploeh.dk/2010/02/03/ServiceLocatorisanAnti-Pattern/" rel="nofollow">and it appears that service location is a concept that has fallen out of favor</a>).</p>
  
  <p>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.</p>
  
  <p>I can't find any way of doing this. How are other developers doing this without a IoC container that supports IServiceLocator (or similar)?</p>
  
  <p>Notes:</p>
  
  <ul>
  <li>the only MVVM library I'm using is Josh Smith's MvvmFoundation.Wpf.</li>
  <li>I've seen the blog post <a href="http://kellabyte.com/2010/08/23/use-ninject-to-decouple-discovery-of-your-viewmodels-in-mvvmlights-viewmodellocator/" rel="nofollow">Use Ninject to decouple discovery of your viewmodel's in mvvmlight's viewmodellocator</a> but this method doesn't seem right.</li>
  </ul>