title: MVC3 Controller constructor + Ninject
body: <p>I'm at the moment working on a MVC3 Web application and ecountered a new problem with Ninject.</p>
  
  <p>I'm using the following code in my controller:</p>
  
  <pre><code>public class TestController : Controller
  {       
      public IRepository&lt;CustomerModel&gt; rep;
  
      public TestController(IRepository&lt;CustomerModel&gt; repository)
      {
          this.rep = repository;
      }
  
      public ActionResult Index()
      {
          return View();
      }
  }
  </code></pre>
  
  <p>And my Ninject Module:</p>
  
  <pre><code>public class RepositoryModule : NinjectModule
  {
      public override void Load()
      {
          Bind(typeof(IRepository&lt;&gt;)).To(typeof(Repository&lt;&gt;));
      }
  }
  </code></pre>
  
  <p>However this just throws me "System.MissingMethodException: No parameterless constructor defined for this object." when I try to render the Index view.</p>
  
  <p>If I then add:</p>
  
  <pre><code>public TestController() : this(new Repository&lt;CustomerModel&gt;(new XenCRMEntities())) { }
  </code></pre>
  
  <p>so my actually TestController looks like:</p>
  
  <pre><code>public class TestController : Controller
  {       
      public IRepository&lt;CustomerModel&gt; rep;
  
      public TestController() : this(new Repository&lt;CustomerModel&gt;(new XenCRMEntities())) { }
  
      public TestController(IRepository&lt;CustomerModel&gt; repository)
      {
          this.rep = repository;
      }
  
      public ActionResult Index()
      {
          return View();
      }
  }
  </code></pre>
  
  <p>It works, but as you can see the new constructor pretty much break the whole point of IoC.</p>
  
  <p>How do I fix this?</p>
  
  <p>Thanks in advance.</p>