0
我想訪問Application_BeginRequest()方法中的Ninject內核。所以我在HttpContext.Current.Items
中設置了Kerne。在Global.asax中創建全局Ninject內核
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()
方法無效的到來。