[英]What's the difference between a Repository and a Finder in Seedstack?
I'm Using Seedstack 16.7 and its Business framework with JPA plugin support.我正在使用 Seedstack 16.7 及其带有 JPA 插件支持的业务框架。
There's 2 ways to acquire data from a datasource.有两种方法可以从数据源获取数据。
Repositories http://seedstack.org/docs/business/manual/repositories/存储库http://seedstack.org/docs/business/manual/repositories/
Finders http://seedstack.org/docs/business/manual/finders/查找器http://seedstack.org/docs/business/manual/finders/
The only apparent difference between them is that finder is a read only interface to a datasource.它们之间唯一明显的区别是 finder 是数据源的只读接口。
Most of the queries that a finder requires can be done just by calling a repository and converting from a Aggregate to a Dto finder 所需的大多数查询都可以通过调用存储库并将聚合转换为 Dto 来完成
Is there any real difference between them, or on their intended?它们之间有什么真正的区别,或者它们的意图吗? other than stated on this question.
除了在这个问题上说的。
It is somewhat complex to explain it in a few lines because that modeling decission comes from deep understanding of DDD, CQ(R)S, fast readmodels, eventual consistency, etc.用几行来解释它有点复杂,因为建模决策来自对 DDD、CQ(R)S、快速读取模型、最终一致性等的深入理解。
As the manual says: "Query the persistence layer or any data source to obtain objects specific to an interface of the application".正如手册所说:“查询持久层或任何数据源以获取特定于应用程序接口的对象”。 The keyword here is Interface .
这里的关键字是Interface 。 In the case of a graphical UI the use of finders is to retrieve a concrete view to present it in a desktop form or webpage.
在图形 UI 的情况下,查找器的用途是检索具体视图以将其呈现在桌面形式或网页中。 In a non CRUD app the UI should be Task-Based so:
在非 CRUD 应用程序中,UI 应该是基于任务的,因此:
So you have a impedance mischatch betwen UI and Aggregates/Entities.因此,您在 UI 和聚合/实体之间存在阻抗失配。 The best way to resolve this is create, explicitly, a way to deal from persistence to view.
解决此问题的最佳方法是明确地创建一种处理从持久性到视图的方法。 Finders comes into play.
发现者开始发挥作用。
When a user issue a command that implies a change in your domain you have to retrieve an aggegate and use the aggregate root as entry point of the action.当用户发出一个暗示您的域发生变化的命令时,您必须检索一个聚合并使用聚合根作为操作的入口点。 This ensures consistency and invariants (rules) of your domain.
这确保了域的一致性和不变性(规则)。 Aggregate modeling has a lot of nuances (take a look here ) that makes bad idea to try using aggregates and entities for your views.
聚合建模有很多细微差别(请看这里),因此尝试将聚合和实体用于您的视图是个坏主意。 So you need a way to read and build in memory aggregates from data sources.
因此,您需要一种从数据源读取和构建内存聚合的方法。 This is the job of repositories.
这是存储库的工作。 Sometimes repositories gives you extra features that you do not need when retrieve data for views like entity change tracking, creation of unique identifications to persist, etc. You do not need anything of this when dealing with views.
有时,存储库会为您提供在检索视图数据时不需要的额外功能,例如实体更改跟踪、创建要持久化的唯一标识等。处理视图时您不需要任何这些功能。 Repositories comes to play.
存储库开始发挥作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.