It is not uncommon for applications to have a a few wizard like interactions. These interactions can range from simple multi-step data capture to something like making payment. What is unique about these multi-step processes is that if one drops out in the middle one has to start from the beginning, unlike other interaction. In this chapter we are interested in design of such interactions in the service layer. So lets see what is the role of service layer
This implies two variations in our design which we would like to avoid.
a) Since the user data is not complete in intermediate steps, the presentation layer cannot provide them when calling the application service. Hence application service need to adopt to this. Any design change in application service interface or implementation to accommodate this results in dependence on the presentation design. Application layer being lower in the stack should not depend on the design of user interface but should rather depend on business needs.
b) In all other operations the mutation of entities is followed by it getting synchronized and saved to the database.
This can be achieved via application service operation which are agnostic of such concerns supplemented by handling such concerns in the presentation layer. In this approach the application service layer implements only one operation. The presentation layer calls the same operation repeatedly providing partial data except in the last step when the complete data is provided. In each of the intermediate steps the application layer tries to complete the operation and failing with the validation error.
domain validation, Rollback mutated domain model