1) Put your code in App_Start/NinjectWebCommon.cs instead of the global.asax
2) After finishing the tutorials, I got the error "No parameterless constructor defined for this object". This post from StackOverflow has the correct answer! Basically you need these 2 code snippets:
public class NinjectControllerFactory : DefaultControllerFactory
{
private IKernel ninjectKernel;
public NinjectControllerFactory(IKernel kernel)
{
ninjectKernel = kernel;
}
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
return (controllerType == null) ? null : (IController) ninjectKernel.Get(controllerType);
}
}
ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory(Kernel));
No comments:
Post a Comment