简体   繁体   中英

Domain Driven Design Application Services

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:

  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() :

  1. Call domain SecurityService to update user's account.
  2. Call domain AccountingService to initialize user's balance.
  3. 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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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