【发布时间】:2021-06-30 10:20:49
【问题描述】:
我在 ASP.Net Web API 中使用 Unity 作为我的依赖解析器。我使用了here的依赖注入教程。
当尝试使用在 BeginScope 中创建的子容器时,我得到的只是父容器。
我正在尝试通过以下代码在 ActionFilterAttribute 中使用它:
httpActionContext.RequestContext.Configuration.DependencyResolver
和
httpActionContext.ControllerContext.Configuration.DependencyResolver
在这两种情况下,它都返回父容器,而不是在调用 BeginScope 时为该特定请求创建的子容器。
如何让子容器解决依赖关系?这可能吗?
【问题讨论】:
标签: c# asp.net-web-api unity-container