I am using ASP.NET MVC 3 + Ninject in my application which works great with my controllers.
I also have a custom base page class that inherits from WebViewPage and I have setup an interface that I’d like to be injected in that custom base page class.
However, it’s not working (my interfaces are null), and I assume that is because Ninject doesn’t know about System.Web.Mvc.MvcWebRazorHostFactory which I suspect it would have to override or intercept somehow.
Can anyone point me in the right direction on how to allow my custom WebViewPage to use DI?
Here is a possible workaround…Use a KernelPersister to state the kernel, and reference it directly from within your base View. It’s not as pretty and seamless as constructor injection, but it does the trick.
KernelPersister might look like this…
Base view might look like this…