我在ASP.NET 4.0项目(而不是MVC)中配置了Ninject 2,但是当我将该项目部署到IIS主机时,它会崩溃,并出现以下情况:
System.NullReferenceException: Object reference not set to an instance of an object.
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.PipelineModuleStepContainer.GetEventCount(RequestNotification notification, Boolean isPostEvent) +30
System.Web.PipelineStepManager.ResumeSteps(Exception error) +1481
System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb) +132
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +709
我用一个普通的ASP.NET Web应用程序再次测试了这一点,并得到了以下代码的相同崩溃:
protected override IKernel CreateKernel()
{
return Container;
}
private IKernel Container
{
get
{
IKernel kernel = new StandardKernel(new SiteModule());
var module = new OnePerRequestModule();
module.Init(this);
return kernel;
}
}
是否有其他人让Ninject使用ASP.NET 4?
[更新:2010.11.03]
在做了一些研究之后,它看起来可能与onePerRequestModule()模块有关,但是删除这个模块似乎并不能解决我在建议时添加它的问题。
this question
.