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.
+2
A:
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 me some strange behavior coming from MvcServiceLocator as indicated in this post.
Steve Hook
2010-08-02 19:53:25
With a Ninject implementation of IMvcServiceLocator, you don't technically need the NinjectControllerFactory. The DefaultControllerFactory yields to the MvcServiceLocator for controller creation. As long as Ninject has the necessary bindings, it's good to go.
John Nelson
2010-08-02 23:03:58
To add to my above comment, currently the MvcServiceLocator requires a binding for IControllerFactory. If you don't have one (yes, even for DefaultControllerFactory), it will throw that error.
John Nelson
2010-08-02 23:06:09