I'm giving ASP.NET MVC 3 Preview 1 a spin and want to configure ninject with it. Is the best way still to use ninject.web.mvc extension? The sample Scott Gu posts doesn't run. It throws an "Error activating IControllerFactory" exception.
You don't need "Ninject.Web.Mvc" to configure Ninject in MVC 3, as I've blogged in a post titled "Dependency Injection in ASP.NET MVC 3 using Ninject".
I believe Scott Gu's code should read...
public static void RegisterServices(IKernel kernel)
{
kernel.Bind<IProductRepository>().To<SqlProductRepository>();
kernel.Bind<IControllerFactory>().To<NinjectControllerFactory>();
}
Where the NinjectControllerFactory is found in...
using Ninject.Web.Mvc;
So yes, you do still need the mvc extension for Ninject.
Perhaps there is a better/newer way to define the default controller factory in MVC 3, but that is how I did it.
There may also be some strange behavior coming from MvcServiceLocator as indicated in this post.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With