If you create a repository class that encapsulates all of your persistence logic for a given entity, such as PersonRepository, but your repository class does not implement the Unit of Work pattern or the Identity Map pattern, is it still considered a repository? In other words, are Unit of Work and Identity Map required for a repository implementation, or can we just call any class that encapsulates our persistence logic a repository?
如果您创建一个存储库类来封装给定实体的所有持久性逻辑(例如PersonRepository),但您的存储库类不实现工作单元模式或身份映射模式,它是否仍被视为存储库?换句话说,是存储库实现所需的工作单元和身份映射,还是我们可以只调用将持久性逻辑封装到存储库的任何类?
I should add one thing. If a repository does not require these patterns and it's really just a container for persistence methods, then what is the difference between a repository and a DAO (Data Access Object)? Are we just creating multiple names for the same object or are we missing part of what a repository is supposed to be?
我应该补充一点。如果存储库不需要这些模式并且它实际上只是持久性方法的容器,那么存储库和DAO(数据访问对象)之间有什么区别?我们只是为同一个对象创建多个名称,还是我们错过了存储库的部分内容?
4 个解决方案
#1
Yes, it is still a repository.
是的,它仍然是一个存储库。
As for if Repository == DAO, I think Repository should be on business logic layer and DAO should be on data access layer, i.e. I think they are on different layers. So as I understand, Repository calls DAO methods to load and persist data.
至于如果Repository == DAO,我认为Repository应该在业务逻辑层上,而DAO应该在数据访问层上,即我认为它们位于不同的层上。据我所知,Repository调用DAO方法来加载和保存数据。
#2
I'd say the Repository and Unit of Work patterns are orthogonal.
我会说Repository和Unit of Work模式是正交的。
Very frequently, I want a single unit of work to span operations on multiple repositories, so an implementation of that would belong into a higher layer.
通常,我希望单个工作单元跨越多个存储库上的操作,因此其实现属于更高层。
#3
Building on what Sii said - it seems better to me if the repository and the unit of work aren't related. Seperation of concerns?
以Sii所说的为基础 - 如果存储库和工作单元不相关,对我来说似乎更好。分离关注?
#4
When considering separation of concerns, remember that your Repository will have the data storage implementation methods, allowing you to keep that out of your main code. This is helpful for unit testing as well as eventually swapping out your data storage implementation altogether (an example of a data storage implementation would be LINQ-to-SQL in ASP.NET.)
在考虑分离关注点时,请记住您的存储库将具有数据存储实现方法,允许您将其保留在主代码之外。这有助于单元测试以及最终完全交换数据存储实现(数据存储实现的一个例子是ASP.NET中的LINQ-to-SQL。)
#1
Yes, it is still a repository.
是的,它仍然是一个存储库。
As for if Repository == DAO, I think Repository should be on business logic layer and DAO should be on data access layer, i.e. I think they are on different layers. So as I understand, Repository calls DAO methods to load and persist data.
至于如果Repository == DAO,我认为Repository应该在业务逻辑层上,而DAO应该在数据访问层上,即我认为它们位于不同的层上。据我所知,Repository调用DAO方法来加载和保存数据。
#2
I'd say the Repository and Unit of Work patterns are orthogonal.
我会说Repository和Unit of Work模式是正交的。
Very frequently, I want a single unit of work to span operations on multiple repositories, so an implementation of that would belong into a higher layer.
通常,我希望单个工作单元跨越多个存储库上的操作,因此其实现属于更高层。
#3
Building on what Sii said - it seems better to me if the repository and the unit of work aren't related. Seperation of concerns?
以Sii所说的为基础 - 如果存储库和工作单元不相关,对我来说似乎更好。分离关注?
#4
When considering separation of concerns, remember that your Repository will have the data storage implementation methods, allowing you to keep that out of your main code. This is helpful for unit testing as well as eventually swapping out your data storage implementation altogether (an example of a data storage implementation would be LINQ-to-SQL in ASP.NET.)
在考虑分离关注点时,请记住您的存储库将具有数据存储实现方法,允许您将其保留在主代码之外。这有助于单元测试以及最终完全交换数据存储实现(数据存储实现的一个例子是ASP.NET中的LINQ-to-SQL。)