title: How to override the ASP.NET MVC 3 default model binder to resolve dependencies (using ninject) during model creation?
body: <p>I have an ASP.NET MVC 3 application that uses Ninject to resolve dependencies. All I've had to do so far is make the Global file inherit from <code>NinjectHttpApplication</code> and then override the <code>CreateKernel</code> method to map my dependency bindings. After that I am able to include interface dependencies in my MVC controller constructors and ninject is able to resolve them. All that is great. Now I would like to resolve dependencies in the model binder as well when it is creating an instance of my model, but I do not know how to do that.</p>
  
  <p>I have a view model:</p>
  
  <pre><code>public class CustomViewModel
  {
      public CustomViewModel(IMyRepository myRepository)
      {
          this.MyRepository = myRepository;
      }
  
      public IMyRepository MyRepository { get; set; }
  
      public string SomeOtherProperty { get; set; }
  }
  </code></pre>
  
  <p>I then have an action method that accepts the view model object:</p>
  
  <pre><code>[HttpPost]
  public ActionResult MyAction(CustomViewModel customViewModel)
  {
      // Would like to have dependency resolved view model object here.
  }
  </code></pre>
  
  <p>How do I override the default model binder to include ninject and resolve dependencies?</p>