Skip to content

The command execution pipeline

Aaron Hanusa edited this page Feb 4, 2021 · 1 revision

peasy service async sequence

This sequence diagram models the asynchronous command execution pipeline detailing the flow of calls between objects when the command returned from the ServiceBase.InsertCommand method is invoked.

What's going on here?

  1. A client application invokes ServiceBase.InsertCommand, supplying a DTO.
  2. ServiceBase creates an instance of ExecutionContext.
  3. ServiceBase creates an instance of ServiceCommand. Note that there are many constructor arguments left out for the sake of brevity.
  4. The client is returned an instance of the service command created in step 3.
  5. The client invokes ServiceCommand.ExecuteAsync.
  6. ServiceCommand invokes ServiceBase.OnInsertCommandInitializationAsync, passing in the execution context created in step 2 and the DTO from step 1.
  7. ServiceCommand invokes ServiceBase.OnInsertCommandGetRulesAsync, passing in the execution context created in step 2 and the DTO from step 1.
  8. If any rules are returned from step 7, each one is validated, by invoking IRule.ExecuteAsync.
  9. If all rules are validated successfully:
    1. ServiceCommand invokes ServiceBase.OnInsertCommandValidationSuccessAsync, passing in the execution context create in step 2 and the DTO from step 1.
    2. ServiceBase invokes IDataProxy.InsertAsync, passing in the DTO received from step 1.
    3. ServiceBase receives a new DTO instance created by IDataProxy.InsertAsync.
    4. ServiceBase returns the new instance of the DTO to ServiceCommand.
    5. ServiceCommand instantiates an instance of ExecutionResult, passing in the new DTO instance, and returns it to the client application.
  10. If validation of any of the rules fail:
  11. ServiceCommand instantiates an instance of ExecutionResult, passing in errors from all failed rules, and returns it to the client application.

By overriding methods of ServiceBase, namely OnInsertCommandInitializationAsync, OnInsertCommandGetRulesAsync, and OnInsertCommandValidationSuccessAsync, you have the opportunity to inject initialization logic, business rules, and command logic into the command execution pipeline, respectively.

Clone this wiki locally