title: What is the use of an IoC framework in an MVC application?
body: <p>I'm trying to understand the use of an IoC framework like StructureMap, but i can't help thinking that these "design patterns" are just nonsense, making code just more complex.</p>
  
  <p>Let me start with an example where i think an IoC is somewhat usefull.</p>
  
  <p>I think an IoC can be usefull when dealing with the instantiation of controller classes in an MVC framework. In this case i'm thinking about the .NET MVC framework.</p>
  
  <p>Normally the instantiation of the controller class is handled by the framework. So that means you can't really pass any parameters to the constructor of your controller class.
  This is where an IoC framework can come in handy. Somewhere in an IoC container you specify what class should be instantiated and passed to your controllers <code>constructor</code> when the controller class is invoked.</p>
  
  <p>This is also handy when you want to unit test the controller, because you can mock the object that is passed to it.</p>
  
  <p>But like i said, i can somewhat understand why people want to use it for their controller classes. But not outside of that. From there on you can simply do normal <em>Dependency Injection</em>.</p>
  
  <p>But why not simply do it like this:</p>
  
  <pre><code>public class SomeController
  {
      public SomeController() : this( new SomeObj() ) 
      {
      }
  
      publiv SomeController(SomeObj obj)
      {
          this.obj = obj;
      }
  }
  </code></pre>
  
  <p>Now you don't have to use any 3rd party IoC framework which also means a lower learning curve. Since you don't have to go into the specs of that framework aswell.</p>
  
  <p>You can still mock the object in your Unit Tests. So no problem there either.</p>
  
  <p>The only thing you can say is, "but now your class is <em>tightly coupled</em> to <code>SomeObj</code>".
  This is true. But who cares!? It's a controller class! I'm not going to reuse that class, ever.. So why on earth should i worry about that tight coupling..? I can mock the object that is passed to it. That's the only important thing.</p>
  
  <p>So why should i bother using an IoC? Am i REALLY missing the point...? To me the IoC pattern is just some overrated pattern. Adding more, complex layers to your application...</p>