统一容器和工作单元(MVC)之间的区别

Difference between unity container and unit of work (MVC)

统一容器和工作单元(如果有的话)有什么区别,据我所知两者都在做同样的事情,但是如何确定使用哪一个。

我需要确定,我理解得很好,没有任何区别。

Unity是一种inversion of control container, where inversion of control is a design pattern, and unit of work是另一种设计模式...

两者的主要区别在于它们是完全不同的设计模式,没有标准可以匹配两种模式并找出相似之处。

OP 说...

I didn't know about inversion of control, read that link and have done some search, but still both are related with dependency injection and no one uses combination of them(both of it), they are using just one of them

依赖注入是一种控制反转的方法。

另一方面,工作单元与控制反转或依赖注入无关。同样,control/dependency 注入的工作单元和反转是不同的设计模式。

也许你可以在一个工作单元中注入依赖关系,或者在某个地方注入一个工作单元,将你的架构与所谓工作单元的具体实现解耦。 仅仅了解设计模式可以合作构建软件堆栈,这与比较两种设计模式有很大的不同

您的 Ioc 容器 unity 可能包含也可能不包含在使用工作单元的另一端的硬实现。您将使用一些特定的 class 来实现您的接口,这些 class 满足您的通用接口定义,但使用特定的后备存储,例如 Entity Framework、LinqToSql、Ado Sql 命令、测试存根等等。如果您使用的是 Ado sql 命令,工作单元将不适用,因此在您的 ioc "service contracts" 中只包含通用功能通常是个好主意。