I am actually reading a book called "DDD in PHP", to help me understand the Domain Driven Design. So far everything is good, but I struggle to understand how to implement one specific topic without coupling Bounded Contexts: Domain Events
Let's say I have to BCs :
When an Order
is placed, an OrderCreated
Event is dispatched.
The Payments
BC catches this event with a subscriber, and creates the invoice.
The problem is, If I want to perfectly separate both BCs, where should the OrderPlaced
Event live, since it's used by both BCs ? Should it live outside both BCs ? In both of them ? What if I want to deploy the Invoices module as a standalone, without having access to the Orders module, and its OrderPlaced event definition, would it cause some fatal errors ?
Thank you in advance for the answers !
The problem is, If I want to perfectly separate both BCs, where should the OrderPlaced Event live, since it's used by both BCs ? Should it live outside both BCs ? In both of them ?
I would store the event in the context that owns it, i.e. the Orders context. How do you intend on separating the contexts? is it a physical / network boundary separation, or just conceptual?
What if I want to deploy the Invoices module as a standalone, without having access to the Orders module, and its OrderPlaced event definition, would it cause some fatal errors ?
It depends on what you are doing with OrderPlaced. If you are subscribing to it from some sort of event stream, then reacting to it inside InvoicesBC by way of converting it to an internal-to-invoices concept, then you'll probably be fine as you could just not deploy the subscriber. If your code in InvoicesBC can run without having to know about OrderPlaced then you should be fine
In general, there are a few ways to deal with this problem: