Domain Services Managed Application Services

I have a question about application services in DDD. For example, I have a rule that when a user confirms registration, the following actions are performed:

  • The user account has been updated so that he can log in.
  • User balance is initialized.
  • The user receives a confirmation letter of registration confirmation.

Considering the SecurityAppService application service, can it contain the following workflow when calling the ConfirmRegistration() method:

  • Call the SecurityService domain to update the user account.
  • Call AccountingService domain to initialize user balance.
  • EmailService call infrastructure for sending email to the user.

The question is as follows. Is AccountingService call legal with SecurityAppService? Or should I include this in the SecurityService call?

+4
source share
2 answers

IMHO, the answer is Yes, this is legal. The service is allowed to call another service when appropriate. In a specific example, this is definitely what you want to do. The real question is how do you manage addiction. Use DI so you can separate the direct connection between the two implementations.

+2
source

You can use the CQRS pattern.

A user user has a Register (User user) method. It will add the user and raise AddUserEvent. AccountService and EmailService implement EventHandlers and get a User object through EventHandlerArgument.

Thus, the SecurityService does not know anything about other services, and all these services are independent.

+3
source

Source: https://habr.com/ru/post/1345410/


All Articles