Not quite sure how to approach this problem regarding DDD.
Say you have 2 domains:
- A
Product
domain which is responsible for creating new and managing existingProducts
which a person has created.Product Aggregate Root
- A
Store
domain which is responsible for assigning all createdProducts
to a givenStore
to be sold, and other stuff. But theStore
can also create newProducts
which will be assigned to themselves but also available for otherStores
so that they can assign theProduct
to themselves.Store Aggregate Root
A Product
can exist without belonging to a Store
. A Store
can exist without having any Products
in it whatsoever (doesn't make sense I know, but this is just a simple example of a complex solution I'm working on atm.)
So when a Person
comes along into the system, they can start at either end. They can start by creating new Products
or they can start by adding a new Store
.
Here is where it gets complicated, when they create a new Store
, they are given the option to add existing Products
or they can create a new Product
and add it to the Store
.
How do you deal with this use case. is the does the Store
have a behavior to CreateNewProduct
where it's responsible to setting up the new Product
and then adding it to the Store
. Or do you simply create a new Product
outside the Store
Domain as part of the Product
domain, and tell the Store
to AddProduct
/ AddExistingProduct
?
UPDATE: Would something like this be appropriate as a Domain Service
public class StoreProductService {
public Store CreateNewStoreProduct (Store store, string sku, string name, etc){
Product newProduct = ProductFactory.CreateNewProduct(sku, name, etc);
store.AddProduct(newProduct);
return store;
}
}