I'm new to DDD and I'm trying to figure out the aggregate root. I'm sure this question has been asked a million times.
So I have :
- Products (thousands)
- Catalogs (hundreds)
- CatalogEntries that associate a product to a catalog and a price (prices are different depending on the catalog)
A catalog can exist without a product and a product can exist without a catalog so I have at least 2 aggregates:
- Product
- Catalog
But where does CatalogEntries go ? If I delete a catalog I need to delete all it's entries but if I delete a product I need to delete all entries from this product too.
If product is the aggregate and I delete a catalog, I need load all my products to remove it and if Catalog is the aggregate I need to load all my catalogs to remove it. I doesn't make sense.
So is it a good idea to have ProductEntry as an aggregate root ? But it can't really live without a product or a catalog, what I thought was the goal of an aggregate.
Product
need to be aware of it'sCatalog
or visa versa in order to enforce business rules? As it stands the behavior you intend to model is trivial and needn't belong on eitherProduct
orCatalog
. Simply adding an additional aggregate (Inventory
) with simple methods likeInventory.Add(productId, catalogId, price)
,Inventory.RemoveProduct(productId)
, andInventory.RemoveCatalog(catalogId)
seems like a straightforward solution.