服务层中的服务组织?
我有一个包含大量不同实体的 Java 服务器应用程序。到目前为止,每个实体顶级实体都有自己的CRUD 服务。我所说的顶层是指可以独立存在的实体树的根。
现在我正在进入 Flex 客户端的核心,发现我需要/编写许多不同的查询。但最好把这些查询放在哪里呢?
举例来说,我有一个查询,根据与某个“bar”的关联来查找所有“foos”。目前该查询位于“foo”服务(findAllByBar)上,但我发现将其(也?)放在“bar”服务(findFoos)中会非常方便。另一方面,我还可以创建一个查询服务并将所有查询集中在其中。
这里有什么好的做法吗?
I have a Java server application with a ton of different entities. So far, each entity top level entity has its own CRUD service. By top level, I mean the root of a tree of entities that can stand alone.
Now I am getting into the heart of my Flex client and find I am needing/writing many different queries. But where best to put these queries?
Say for example, I have a query to find all "foos" based on their associate with a certain "bar". Currently that query is on the "foo" service (findAllByBar), but I am finding that it would be very convenient to have it (also?) in the "bar" service (findFoos). On the other hand, I could also create a query service and lump all the queries in there.
Whats a good practice to do here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试从以下角度对您的应用程序进行分层:
域:将您的类设计为“Customer”等实体、“Address”或“Color”等值对象以及聚合根(如“Order”,其中包含“LineItem”列表) ”)
存储库:这些是数据访问对于实体,为每个聚合根创建一个存储库(CustomerRepository、OrderRepository,...)
服务:创建由逻辑业务抽象或有界上下文而不是实体组成的粗粒度服务,创建订单服务、商品服务和客户服务是不合逻辑的。这些实体代表订单处理的一个原子业务价值,那么您的服务将使用所有必需的存储库来处理数据访问。
例子:
Try to layer your application in these perspectives:
Domain: design your class as entities like "Customer", value objects like "Address" or "Color", and aggregate roots (like "Order" which includes a list of "LineItem")
Repositories: these are the data access for the entities, create a repository for each aggregat root (CustomerRepository, OrderRepository, ...)
Services: create a coarse grained services spitted by logical business abstractions or bounded context not by entities, it is not logical to create a service for order and a service for items and a service for customers when all these entities are representing one atomic business value of order processing, then your service will use all required repositories to handle the data access.
example:
我会将查询放在各自的类中,而不是创建一个(可膨胀的)查询服务
I would put queries in their respective classes instead of creating one (bloatable)query service