gpt4 book ai didi

abp - 关于使用 DomainService

转载 作者:行者123 更新时间:2023-12-05 02:42:51 34 4
gpt4 key购买 nike

  1. 我不能完全理解在什么情况下我会使用 DomainService 和在这种情况下你的文件不详细在这个问题上足够了。你能给出更详细的解释吗举个例子?
  2. 如果我只使用 ApplicationService 而从不使用,可能会出现什么问题使用 DomainService。
  3. 我应该在 DomainService 中进行哪些操作?
  4. 我应该遵循什么样的方式来区分这两者相互提供服务。

最佳答案

简短回答:只有在需要额外的抽象级别时才使用领域服务。

详细回答如下。

1。什么时候使用域服务?

来自文档 Domain Services #Introduction :

Creating a Domain Service is especially needed when;

  • You implement a core domain logic that depends on some services (like repositories or other external services).
  • The logic you need to implement is related to more than one aggregate/entity, so it doesn't properly fit in any of the aggregates.

文档中的示例 Domain Services #Introduction : 为用户分配问题时,请检查分配的问题数量是否不大于或等于特定数量。

教程中的示例 Part 6: Authors: Domain layer : 更改作者姓名时,请检查是否不存在具有给定姓名的作者。

2。如果我不使用域服务会出现什么问题?

您可能会错过作为核心域逻辑或业务规则的检查。

但一般来说,没问题。来自教程 Part 6: Authors: Domain layer :

DDD tip: Do not introduce domain service methods unless they are really needed and perform some core business rules.

3。领域服务应该做哪些操作?

请参阅#1 和#4 中的示例。

4。如何区分领域服务和应用服务?

来自文档 Domain Services #Application Services vs Domain Services :

While both of Application Services and Domain Services implement the business rules, there are fundamental logical and formal differences;
  • Application Services implement the use cases of the application (user interactions in a typical web application), while Domain Services implement the core, use case independent domain logic.
  • Application Services get/return Data Transfer Objects, Domain Service methods typically get and return the domain objects (entities, value objects).
  • Domain services are typically used by the Application Services or other Domain Services, while Application Services are used by the Presentation Layer or Client Applications.

来自教程Part 8: Author: Application Layer :

  • Used the AuthorManager (domain service) to create a new author.
  • Used the IAuthorRepository.InsertAsync to insert the new author to the database.
  • Used the ObjectMapper to return an AuthorDto representing the newly created author.

DDD tip: Some developers may find useful to insert the new entity inside the _authorManager.CreateAsync. We think it is a better design to leave it to the application layer since it better knows when to insert it to the database (maybe it requires additional works on the entity before insert, which would require to an additional update if we perform the insert in the domain service). However, it is completely up to you.

关于abp - 关于使用 DomainService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67264684/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com