Markus
Markus

Reputation: 3627

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?

Upvotes: 4

Views: 392

Answers (2)

Fadrian Sudaman
Fadrian Sudaman

Reputation: 6465

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.

Upvotes: 2

Gengzu
Gengzu

Reputation: 542

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.

Upvotes: 3

Related Questions