相关疑难解决方法(0)

ASP.NET MVC2 + Ninject + NLog(+共享主机?)= NullReferenceException

我有一个基于Tekpub Starter Site的MVC2应用程序,所以它使用Ninject进行依赖注入,NLog用于日志记录,以及各种各样的其他库.据我所知,正是这些导致了我的问题.

使用ASP.NET开发服务器(Cassini)在我的PC上工作得非常好但是当我部署到服务器(这是一个廉价的共享主机交易)时,我得到一个NullReferenceException似乎与Ninject实例化记录器有关.

这是我的Global.asax.cs的相关位

protected override void OnApplicationStarted() {
    Logger.Info("App is starting"); // <-- I think this is what's causing the problem

    RegisterRoutes(RouteTable.Routes);
    //MvcContrib.Routing.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
    RegisterAllControllersIn(Assembly.GetExecutingAssembly());
    SetEngines();
}

protected override IKernel CreateKernel() {
    return Container;
}

internal class SiteModule : NinjectModule {
    public override void Load() {
        Bind<ILogger>().To<NLogLogger>();
        // and a couple of others...
    }
}

protected void Application_End() {
    Logger.Info("App is shutting down");
}

protected void Application_Error() {
    Exception lastException = Server.GetLastError();
    Logger.Fatal(lastException);
}

public ILogger Logger …
Run Code Online (Sandbox Code Playgroud)

dependency-injection shared-hosting ninject nlog asp.net-mvc-2

14
推荐指数
2
解决办法
4143
查看次数