title: Default constructor vs IOC container
body: <p>Can someone explain to me the advantages of using an IOC container over simply hardcoding the default implementation into a default constructor?</p>
  
  <p>In other words, what is wrong about this code?</p>
  
  <pre><code>public class MyClass
  {
      private IMyInterface _myInterface;
  
      public MyClass()
      {
          _myInterface = new DefaultMyInterface();
      }
  
      public MyClass(IMyInterface myInterface)
      {
          _myInterface = myInterface;
      }
  }
  </code></pre>
  
  <p>As far as I can tell, this class supports constructor injection enough so unit testing and mocking is easily done.  In addition to which, the default constructor removes the computational overhead of the IOC container (not to mention the whole process is a lot more transparent).</p>
  
  <p>The only benefits i can see to using an IOC container is if you need to switch out the implementation of your interfaces frequently.  Am I missing something?</p>