SimpleInjector,OWIN和ASP.Net MVC集成

时间:2016-03-20 23:13:17

标签: asp.net-mvc owin simple-injector

根据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请求的范围内。

需要专家的一些澄清......:)

由于

1 个答案:

答案 0 :(得分:0)