Ninject-ing a dependency in Global.asax

前端 未结 4 597
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-29 11:56

I\'m starting a web application with MVC3 and Ninject. There is one dependency that I also need in the Global.asax file that needs to be a singleton.

I thought it sh

4条回答
  •  太阳男子
    2020-12-29 12:16

    Can you use the HttpApplication.Appliction property?

    public class MyHttpApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            this.Application["auth"] = GetAuthFromContainer();
        }
    
        protected void Application_AuthenticateRequest()
        {
            IUserAuthentication auth = (IUserAuthentication)this.Application["auth"]; 
            // auth != null
        }
    }
    

提交回复
热议问题