根据SimpleInjector documentation,我们可以定义一个将在OWIN请求中生效的范围。
public void Configuration(IAppBuilder app) {
app.Use(async (context, next) => {
using (container.BeginExecutionContextScope()) {
await next();
}
});
}
但是,调用container.GetCurrentExecutionContextScope()在ASP.Net控制器的操作中调用它时总是返回null。
[HttpGet]
public void MyAction()
{
// Here scope is always null
var scope = Container.GetCurrentExecutionContextScope();
}
我认为它不应该为null,因为控制器动作调用在OWIN请求的范围内。
需要专家的一些澄清......:)
由于
答案 0 :(得分:0)
首先,请更新您的Simple Injector。
与OWIN集成的文档:https://simpleinjector.readthedocs.io/en/latest/owinintegration.html
ASP.NET MVC:https://simpleinjector.readthedocs.io/en/latest/mvcintegration.html