title: ObjectId Model Binding with Web Api 2
body: <p>I'm using MongoDB with an ASP.NET Web Api (2) application, and want to accept ObjectId arguments in the Web Api methods.</p>
  
  <p>I've written a custom model binder for the ObjectId type, and it when adding it to the Get method of a controller, everything works.</p>
  
  <p><code>[Route("{id}")]
  public HttpResponseMessage Get(String type, [ModelBinder(typeof(ObjectIdModelBinder))]ObjectId id) {</code></p>
  
  <p>But I need to do this in several methods and controllers, so I would rather put it somewhere central. I've read that I can register the binder centrally like this:</p>
  
  <pre><code>public static void Register(HttpConfiguration config) {
      var provider = new SimpleModelBinderProvider(typeof(ObjectId), new ObjectIdModelBinder());
      config.Services.Insert(typeof(ModelBinderProvider), 0, provider);
  }
  </code></pre>
  
  <p>But that's not working!</p>
  
  <p>Any ideas? Not really sure what the config.Services collection should contain, but I'm having a hard time locating the binder I insert.</p>