代码之家  ›  专栏  ›  技术社区  ›  Richard Slater

Ninject+.NET 4+集成管道导致NullReferenceException

  •  2
  • Richard Slater  · 技术社区  · 15 年前

    我在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 .

    1 回复  |  直到 15 年前
        1
  •  2
  •   Ruben Bartelink    15 年前

    在Ninject 2中,您使用 Ninject.Web 扩展( see the complete set here )不要像这里那样做任何明确的配置 OnePerRequestModule 等。

    你也不做任何web.config的事情iirc(我正在使用 the MVC one 你不在那里)

    推荐文章