ninject/Ninject.Web.Common — Issue #4: RC2, issue with HttpApplicationInitializationHttpModule Injection
Author: jpknoll
Created: 2012-03-08 20:54:44+00:00
State: open

If my webservice global inherits from NinjectHttpApplication, then the application fails with the following error:

Error activating IntPtr
No matching bindings are available, and the type is not self-bindable.
Activation path:
3) Injection of dependency IntPtr into parameter method of constructor of type Func{IKernel}
2) Injection of dependency Func{IKernel} into parameter lazyKernel of constructor of type HttpApplicationInitializationHttpModule
1) Request for IHttpModule

The following code resolved this error:

public class Global : NinjectHttpApplication
{
protected override void OnApplicationStarted()
{
base.OnApplicationStarted();
}

protected override IKernel CreateKernel()
{
//define modules loaded by default
var modules = new INinjectModule[]
{
new ServiceModule(),
new EntityContextModule(),
};

IKernel kernel = new StandardKernel(modules);

//hack for Ninject.Web.Common.HttpApplicationInitializationHttpModule
kernel.Bind>().ToMethod(c => () => GetKernelInstance());

return kernel;
}

private IKernel GetKernelInstance()
{
//this method is deprecated
return this.Kernel;
}
}

Is this intended?