我正在将 MVC 3 与 Ninject 一起使用。我在 CreateKernel 方法中定义了 Global.asax.cs(一个 NinjectHttpApplication)中的所有绑定。
我还有一个为所有页面请求运行的 HTTP 模块。在执行 CreateKernel 方法后,模块在 PreRequestHandlerExecute 上运行其逻辑。
我想让 HTTP 模块通过将类类型链接到模块负责构建的特定实例变量来定义新的绑定。这可能吗?
基本上,在 HttpModule 中,我试图运行这个:
IUserContext userContext = userContextManager.GetUserContext();
Kernel.Bind<IUserContext>().ToConstant(userContext).InRequestScope();