Ninject.Web, OnePerRequestModule, and IIS7 Integrated Pipeline
- by Ted
Using Ninject.Web with ASP.NET WebForms project. Works without issues using classic pipeline, but when it's under integrated pipeline, a null reference exception occurs on every request (which I've narrowed down to the use of the OnePerRequestModule):
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.PipelineStepManager.ResumeSteps(Exception error) +1216
System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb) +113
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +616
The above always occurs unless I remove the OnePerRequestModule initializization. occurs consistently on a very basic test app I put together. On a standard app where I actually want to implement it, I can solve the issue by initializing the OnePerRequestModule like so:
protected override IKernel CreateKernel()
{
// This will always blow up.
//var module = new OnePerRequestModule();
//module.Init(this);
IKernel kernel = new StandardKernel(new MyModule());
// This works on larger app, but on basic app, it makes no difference under integrated pipeline as the above exception is always thrown.
var module = new OnePerRequestModule();
module.Init(this);
return kernel;
}
Before I start spelunking further, is anybody out there using Ninject.Web extension successfully under the integrated pipeline in IIS7 AND using the OnePerRequestModule? There are certain restrictions for modules under the integrated pipeline that weren't there in previous IIS versions/classic pipeline.
Quickly thrown together sample project at http://www.filedropper.com/test_59
And in case it's not obvious with Ninject.Web: it's an ASP.NET WebForms project.