This is an MVC application where the controllers need a DataContextCreator
and a CustomerID
in the constructor. My ControllerFactory
looks like:
public class NinjectControllerFactory : DefaultControllerFactory
{
private IKernel ninjectKernel;
public NinjectControllerFactory()
{
ninjectKernel = new StandardKernel();
AddBindings();
}
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
if (controllerType == null)
{
return null;
}
else
{
string customerID = requestContext.HttpContext.Session["CustomerID"].ToString();
return (IController)ninjectKernel.Get(controllerType, new IParameter[]{new Parameter("CustomerID", customerID, true)});
}
}
private void AddBindings()
{
ninjectKernel.Bind<IDataContextCreator>().To<DefaultDataContextCreator>();
}
}
I get the following error when navigating to the Page i.e. triggering the creation of the Controller:
Ninject.ActivationException: Error activating int
No matching bindings are available, and the type is not self-bindable.
Activation path:
2) Injection of dependency int into parameter CustomerID of constructor of type MyController
1) Request for MyController
All of the above is using MVC3 .Net 4 on Win 7. Thanks for your help.