I need to wire my custom ModelBinder up to my DI container in MVC 3, but I can't get it working.
So. This is what I have: A ModelBinder with a constructor injected service.
public class ProductModelBinder : IModelBinder{
public ProductModelBinder(IProductService productService){/*sets field*/}
// the rest don't matter. It works.
}
My binder works fine if I add it like this:
ModelBinders.Binders.Add(typeof(Product),
new ProductModelBinder(IoC.Resolve<IProductService>()));
But that is the old way of doing it, and I don't want that.
What I need is help on how to hook that modelbinder up to the IDependencyResolver I've registered.
According to Brad Wilson the secret is using a IModelBinderProvider implementation, but its very unclear as to how to wire that up. (in this post)
Does anyone have an example?