【发布时间】:2016-10-07 19:36:16
【问题描述】:
我在 Web API 2 应用程序中使用 Unity 和实体框架。我用HierarchicalLifetimeManager.注册类型
var container = new UnityContainer();
container.RegisterType<IService, Service>(new HierarchicalLifetimeManager());
我是否需要将所有 dbContext 调用包装在这样的 using 语句中?需要这个吗?我认为 Unity 会为我处理上下文。
using (var client = new dbContext())
{
var result = client.Customers.toList();
}
或者我可以只使用没有using 语句的dbContext 吗?
【问题讨论】:
-
如果你这样做
var client = new dbContext(),Unity与上下文的生命周期无关。
标签: entity-framework asp.net-web-api2 unity-container