I am in the process of adopting DDD concepts to develop our next projects, and more specifically, CQRS.
After reading a lot of things, I am now trying to implement a simple concept concept.
The fact is that I got stuck right after I started: p
I am trying to apply this approach to a simple user registration process, where are the steps:
- The user fills out the registration form and sends a request
- The application creates a user
- The application authenticates the user (automatic login)
- Application sends confirmation email to user
- The application redirects the user to another place using a confirmation message
In terms of implementation, so far I get the following:
- Controller action maps request data to RegisterCommand object
- Controller actions require the command bus to process RegisterCommand
- The "register" method of the command handler (UserService) creates a new user object (whether it be a new command or a factory object)
- Model creates RegisterEvent register
- The command handler asks the repository to save the new user object
To do this, the controller action does not know about it.
So, I suppose that everything in this context should be executed synchronously (except for sending by email), I can use the direct / synchronous command bus and in the controller action right after the command bus is called, I can request read-only "(query database), and if it exists, suppose everything went well, so I can give the user confirmation.
The automatic registration process is handled by an event handler.
Assuming this is correct, what if something goes wrong, how to tell the user the right information?
A common example is often used in articles that we can find over the Internet: a customer pays for his order using an expired credit card. The system accepts the request, informs the user that everything is in order, but after a few minutes the user receives an email with the message that his order cannot be processed.
Well, this scenario is acceptable in many cases, but for some others it is simply not possible. So where are the examples regarding these use cases ?: P
Thanks!