简体   繁体   English

Seedstack 中的 Repository 和 Finder 有什么区别?

[英]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.有两种方法可以从数据源获取数据。

  1. Repositories http://seedstack.org/docs/business/manual/repositories/存储库http://seedstack.org/docs/business/manual/repositories/

    • They are pretty much the ones that acts in behalf of an traditional EntityManager on JPA, keeping the type safety.它们几乎是代表 JPA 上传统 EntityManager 的那些,保持类型安全。
  2. Finders http://seedstack.org/docs/business/manual/finders/查找器http://seedstack.org/docs/business/manual/finders/

    • They retrieve Dto from a datasource.他们从数据源中检索 Dto。

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、快速读取模型、最终一致性等的深入理解。

  • Finders发现者

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 应该是基于任务的,因此:

  1. Your views does not match your Entities and Aggregates.您的观点与您的实体和聚合不匹配。
  2. Your Entities and Aggregates does not (should not) contain the full lists of selection data ie: States and Cities (classic cascading dependency comboboxes)您的实体和聚合不(不应该)包含选择数据的完整列表,即:州和城市(经典的级联依赖组合框)
  3. Your Aggregates and Entities does not (should not) contain the full list of referenced Entities (A Customer class with a hurge list of Orders, with all order data, placed inside is wrong DDD aggregate modeling) but somewhere in your app you have to show full order list.你的聚合和实体不(不应该)包含引用实体的完整列表(一个带有大量订单列表的客户类,所有订单数据,放在里面是错误的 DDD 聚合建模)但是你必须在你的应用程序中的某个地方显示完整的订单清单。
  4. Your Views and Aggregates can be retrieved from different data sources (usually for query performance and/or eventural consistency).可以从不同的数据源检索您的视图和聚合(通常用于查询性能和/或最终一致性)。 ie NoSql readmodels, a non normalized relational database or precomputed views (instead of tables representing your Entities) in your domain relational database.即 NoSql readmodels,一个非规范化的关系数据库或域关系数据库中的预计算视图(而不是代表您的实体的表)。

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.发现者开始发挥作用。

  • Repoisitories仓库

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.

相关问题 "Spring 中的@Repository 和@RepositoryDe​​finition 有什么区别?" - What's the difference between @Repository and @RepositoryDefinition in Spring? Spring 中的@Component、@Repository 和@Service 注解有什么区别? - What's the difference between @Component, @Repository & @Service annotations in Spring? 如何处理@Component和@Repository / @Service注释之间的区别是什么? - What's the difference between how @Component and @Repository / @Service annotations are processed? #{} $ {}和%{}之间有什么区别? - what's the difference between #{} ${} and %{}? @Entity 和 @Repository 注释有什么区别? - What is the difference between @Entity and @Repository annotations? @RepositoryRestController和@Repository注释之间有什么区别? - What is the difference between @RepositoryRestController and the @Repository annotations? JPA Repository 中的 DateGreaterThanEqual 和 DateIsGreaterThanEqual 有什么区别? - What is the difference between DateGreaterThanEqual and DateIsGreaterThanEqual in JPA Repository? 与使用存储库相比,使用服务有什么区别? Spring 开机 - What's the difference between using a Service compared to using a repository? Spring Boot 这两个ifs有什么区别? - What's the difference between these 2 ifs? 用最简单的术语来说,同步到存储库和更新到 HEAD 之间有什么区别? - In the simplest terms, what is the difference between synchronize to repository and update to HEAD?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM