title: Using a ServiceLocator in Class LIbraries and MVC DependencyResolver
body: <p>I've really gotten into the DI/IoC things - it makes some things a lot easier. However, I have a few inherited classes that implement a class with a required parameterless constructor, I thus use a service locator to get what I want:</p>
  
  <pre><code>MyMembershipProivder() : MyMembershipProvider(ServiceLocator.Current.GetInstance&lt;...&gt;){}
  MyMembershipProivder(IMemberRepo memberRepo){...}
  </code></pre>
  
  <p>Works perfect. However, since I'm also using MVC3 DependencyResolver I find myself no other way but to do:</p>
  
  <pre><code>var locator = new NinjectServiceLocator(kernel);
  DependencyResolver.SetResolver(locator);
  ServiceLocator.SetLocatorProvider(() =&gt; locator);
  </code></pre>
  
  <p>DependencyResolver gets used within the MVC app and the ServiceLocator gets used throughout the various class libraries.</p>
  
  <p>Is this the ideal way to do this? Am I missing something?</p>
  
  <p><strong>Update</strong></p>
  
  <p>In the example above, the class is a custom asp.net mebership provider. The asp.net membership provider factory requires for my custom provider to have a parameterless constructor, forcing me to use the service locator to inject the repository that it uses internally.</p>