【发布时间】:2016-05-23 08:51:02
【问题描述】:
我想在 Application_BeginRequest() 方法中访问 Ninject Kernel。所以我在HttpContext.Current.Items中设置了Ker nel。
public class WebApiApplication : HttpApplication
{
public IKernel Kernel
{
get { return (IKernel) HttpContext.Current.Items["Context"]; }
set { HttpContext.Current.Items["Context"] = value; }
}
protected void Application_Start()
{
.....
Kernel = new StandardKernel();
GlobalConfiguration.Configuration.DependencyResolver =
new NinjectDependencyResolver(Kernel);
Debug.WriteLine("Application started with kernel: {0}", Kernel);
}
protected void Application_BeginRequest()
{
Debug.WriteLine("Application begin request with kernel: {0}", Kernel);
}
我启动应用程序,但内核对象在 Application_BeginRequest() 方法中为空。
【问题讨论】:
标签: c# asp.net-web-api ninject ninject.web.mvc