title: web api model binding to an interface
body: <p>I'm trying to bind a controller action to an interface but still maintain the default binding behavior.</p>
  
  <pre><code>public class CoolClass : ISomeInterface
  {
      public DoSomething {get;set;} // ISomeInterface
  }
  
  public class DosomethingController : ApiController
  {
      public HttpResponseMessage Post(ISomeInterface model)
      {
          // do something with model which should be an instance of CoolClass
      }
  } 
  </code></pre>
  
  <p>The consumer of my service knows nothing of CoolClass so having them add "$type" to the Json they are passing would be a hack in my opinion. I'd like to be able to handle it in the service. If I specify CoolClass as the action parameter it works fine.</p>
  
  <p>EDIT: So I found a partial solution to my question here <a href="https://stackoverflow.com/questions/13950395/dependency-injection-for-asp-net-web-api-action-method-parameters">Dependency injection for ASP.NET Web API action method parameters</a> but there is a follow up issue. That solution does not resolve interface properties. See my example below.</p>
  
  <p>IConcreteClass will be resolved, but ISubtype will not.</p>
  
  <pre><code>public class SubConcreteClass : ISubtype
  {
      // properties
  }
  
  public class ConcreteClass : IConcreteClass
  {
      public ISubtype Subtype {get;set;}
  }
  </code></pre>
  
  <p>Once the media formatter sees that is can resolve the type in IConcreteClass, it then reads the entire stream. So I'm guessing there is no chance to resolve interface members.</p>