我按照下面链接的示例来设置统一以使用我的服务层.我的项目设置与本文中的项目非常相似,我理解除了为什么在注册服务依赖项时使用PerThreadLifetimeManager的所有内容.请记住,我也在使用我的服务层中使用的通用存储库和单元工作.大多数统一示例使用默认(瞬态)生命周期管理器,因为我的设置类似于下面的设置,我想知道为什么我应该使用PerThreadLifeimeManager?我正在为我当前的表示层使用ASP.NET Web表单项目,如果它发生了任何变化.
container.RegisterType<ICatalogService, CatalogService>(new PerThreadLifetimeManager())
Run Code Online (Sandbox Code Playgroud)
dependency-injection unity-container unit-of-work object-lifetime repository-pattern
unit-of-work ×1