title: Making dependency injection optional by introducting a factory?
body: <p>So I have a piece of software containing a brunch of service classes. Those services take some dependencies though their respective constructors.</p>
  
  <p>I have designed with dependency injection in mind, but developers who are going to build on top of the software, may not want to use DI. Therefore I have <strong>not</strong> implemented an IOC container, so it is up to the developer to introduce one if desired.</p>
  
  <p>My problem is that the software comes with an administration website, which uses these services.
  I don't want to hardcode the service dependencies in the site, because I want to make it possible for the developers to switch them if they want to.</p>
  
  <p>So how should I go about this?</p>
  
  <p>I was thinking about introducing a factory for services, and give it a fixed static location somewhere. Then use it on the site.</p>
  
  <pre><code>public class ServiceFactory : IServiceFactory
  {
      public static IServiceFactory Current { get; set; }
  
      static ServiceFactory()
      {
          Current = new ServiceFactory();
      }
  
      public TService Create&lt;TService&gt;()
      {
          // Creation logic here.
      }
  }
  </code></pre>
  
  <p>Developers will be able to control things by setting their own implementation of <code>IServiceFactory</code> to the static <code>ServiceFactory.Current</code> property.</p>
  
  <p>Is this the way to go?</p>