I have 2 separate aggregate roots product
with own entities and VO's and manufacturer
.
And there are manyToMany relation to between them.
If we looking from product
aggregate perspective, product
can have many manufacture
and should have at least one.
If we looking from manyfacturer
perspective, it can have no or many product
Let's think only about product
aggregate. Product aggregate should not know about manufacturer, it simply need only manufacturer id and that's it, but... from other side I do not what product to have link to invalid/unexisting manufacturer.
As far as I know it's bad practice to make a call to another aggregate to make sure it exists, right? How can I do it, can I run some query like IsManufacturerExist
from the product related command while updating product??? In case if product has invalid manufacturer, it's mean product it self invalid, and I do not want to have product in invalid state.
More or less same if we will look to manufacturer aggregate side.
thanks for any help!
How can I do it, can I run some query like IsManufacturerExist from the product related command while updating product???
I think you are talking about the same problem described here.
The two common answers
The second of these approaches is where you see the "DomainService" pattern appear.
Both of these approaches have a specific consideration baked into them: that you aren't worried about race conditions; in other words, what is supposed to happen if the manufacturer is changing concurrently with the change to the product?
If getting that wrong is expensive, then you'll either need to introduce a locking strategy or a redesign of your models. If it isn't expensive, then you may be able to get by with Memories, Guesses and Apologies.