I had a similar problem today actually so it's funny you should add
this. I think it is very context specific to your problem so my
answer may not help you.
In my case the general concept being modeled is that of a product
catalog. I decided (for now at least the domain model will probably
be refactored a few more times) to model two aggregates:
Product (which encapsulates the state and exposes the behavior of an
individual product)
Catalog (which encapsulated more general concepts about the catalog
including categories and some other stuff)
The behaviors are going to look a bit like this (I'm going to
encapsulate the arguments to save some typing)
So adding a category to a catalog is pretty simple and the state
change would be handled by the event:
Catalog.CreateCategory(CategoryInfo categoryInfo){
ApplyEvent(new CategoryCreated(categoryInfo));
}
Then adding a product to that category would start with this command:
CommandHandler.Execute(AddProductToCategoryCommand command) {
var catalog = repository.Get<Catalog>(command.CatalogId);
var product = repository.Get<Product>(command.ProductId);
catalog.AddProductToCategory(product, command.CategoryName)
}
Catalog.AddProductToCategory(Product product, string categoryName) {
if (CatalogContainsCategory(categoryName))
product.AddToCategory(_categories[categoryName]);
}
Product.AddToCategory(CategoryInfo catInfo) {
ApplyEvent(new ProductAddedToCategory(catInfo));
}
Again this isn't exactly the code, but it's the gist of it. I worked
some of this out today, so it's certainly not perfect and like you I'd
love some feedback on the ideas presented here.
Chris