简体   繁体   English

域驱动设计应用服务

[英]Domain Driven Design Application Services

I have a question regarding application services in DDD. 我对DDD中的应用程序服务有疑问。 For instance, I have a rule that when a user confirms registration the following actions take place: 例如,我有一条规则,当用户确认注册时,会发生以下操作:

  1. User's account is updated so that he can login into the system. 用户的帐户已更新,以便他可以登录系统。
  2. User's balance is initialized. 用户的余额已初始化。
  3. User receives a confirmation letter that the registration was confirmed. 用户收到确认登记的确认函。

Given an application service SecurityAppService, can it can contain the following workflow on calling its method ConfirmRegistration() : 给定应用程序服务SecurityAppService,它可以在调用其方法ConfirmRegistration()包含以下工作流:

  1. Call domain SecurityService to update user's account. 调用域SecurityService以更新用户的帐户。
  2. Call domain AccountingService to initialize user's balance. 调用域AccountingService来初始化用户的余额。
  3. Call infrastructure EmailService to send an email to the user. 调用基础架构EmailService以向用户发送电子邮件。

The question is the following. 问题如下。 Is the call to AccountingService legal from the SecurityAppService? 从SecurityAppService调用AccountingService是否合法? Or I should include that into the call to the SecurityService? 或者我应该将其包含在对SecurityService的调用中?

You can use CQRS pattern. 您可以使用CQRS模式。

UserManager has Register(User user) method. UserManager具有注册(用户用户)方法。 He will add user and raise the AddUserEvent. 他将添加用户并引发AddUserEvent。 AccountService and EmailService implements EventHandlers and receive User object through EventHandlerArgument. AccountService和EmailService实现EventHandler并通过EventHandlerArgument接收User对象。

So, SecurityService nothin knows about other services and all of these services are independent. 因此,SecurityService不知道其他服务,所有这些服务都是独立的。

IMHO, the answer is Yes it is legal. 恕我直言,答案是肯定是合法的。 A service is allowed to call another service when it is appropriate. 允许服务在适当时调用其他服务。 In the particular example, it is definitely something that you want to do. 在特定示例中,它绝对是您想要做的事情。 The real question is how you manage the dependency. 真正的问题是你如何管理依赖。 Use DI so that you can decouple the direct relation between the two implementations. 使用DI可以解耦两个实现之间的直接关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM