Commands, Queries, and Domain Events
September 16, 2023 ยท View on GitHub
Picture yourself embarking on a new project. You're aware that the application you're about to develop will be complex, so you've made a few key decisions:
- You'll be using the Clean Architecture design pattern.
- You aim to neatly segregate the code responsible for processing Queries and Commands.
- You'll be utilizing tactical Domain-Driven Design (DDD) patterns, including the use of Domain Events.
To accomplish this, you'll need to define three separate Pipelines, each tailored to a specific purpose.
Command Pipeline
- Ensures that a given Command contains all the necessary fields for processing the request.
- Validates whether the application layer's required rules are satisfied.
- Command handlers must operate within a transactional context.
Here's how to implement it:
Query Pipeline
- Ensures that the Query data includes all the required fields for processing the request.
Here's how to implement it:
Domain Event Pipeline
- Dispatcher should not create its own Dependency Injection scope (it should be inherited from parent, in that case, from Command Dispatcher)
Here's how to implement it: