领域驱动设计应用服务
我对 DDD 中的应用程序服务有疑问。例如,我有一条规则,当用户确认注册时,会发生以下操作:
- 更新用户的帐户,以便他可以登录系统。
- 用户余额已初始化。
- 用户收到注册已确认的确认信。
给定一个应用程序服务 SecurityAppService,它在调用其方法 ConfirmRegistration()
时是否可以包含以下工作流程:
- 调用域 SecurityService 来更新用户帐户。
- 调用域AccountingService初始化用户余额。
- 调用基础结构 EmailService 以向用户发送电子邮件。
问题如下。从 SecurityAppService 调用 AccountingService 是否合法?或者我应该将其包含在对 SecurityService 的调用中?
I have a question regarding application services in DDD. For instance, I have a rule that when a user confirms registration the following actions take place:
- User's account is updated so that he can login into the system.
- User's balance is initialized.
- 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()
:
- Call domain SecurityService to update user's account.
- Call domain AccountingService to initialize user's balance.
- Call infrastructure EmailService to send an email to the user.
The question is the following. Is the call to AccountingService legal from the SecurityAppService? Or I should include that into the call to the SecurityService?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 CQRS 模式。
UserManager 有 Register(User user) 方法。他将添加用户并引发 AddUserEvent。
AccountService 和 EmailService 实现了 EventHandlers 并通过 EventHandlerArgument 接收 User 对象。
因此,SecurityService 对其他服务一无所知,并且所有这些服务都是独立的。
You can use CQRS pattern.
UserManager has Register(User user) method. He will add user and raise the AddUserEvent.
AccountService and EmailService implements EventHandlers and receive User object through EventHandlerArgument.
So, SecurityService nothin knows about other services and all of these services are independent.
恕我直言,答案是肯定的,这是合法的。
一个服务可以在适当的时候调用另一个服务。在特定的示例中,这绝对是您想做的事情。真正的问题是如何管理依赖关系。使用 DI 可以解耦两个实现之间的直接关系。
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.