Hey all
I have an ASP.net MVC project in the works at the moment, and I'm wondering if the following could be possible: I have a custom ModelBinder class that has a reference to a service (essentially a fetcher) as a dependency. I want the dependency to be injected using an IoC container (currently Ninject) but there seems to be nowhere in the method chain that I can plug in something that says load the model binder from my IoC container.
My first thought is to have a generic object binder that then tries to retrieve a specific ModelBinder from the container, returning null if not found, and then stetting this up as a binder, i.e. something like: ModelBinders.Binders.Add(typeof(object),typeof(NinjectModelBinder));
but I’m unsure
- a) if this will work
- b) if it's really the right thing to do
I could forgo the resolving of the complex object until the Action method but it would be cleaner and more desirable to be able to provide the complex object (which is essentially loaded and built from the data access layer) as a parameter to the action.
Any thoughts/help appreciated.