Still digging into CQRS implementations experiment, and I decided to start over my Blog from scratch and to use it as a Sandbox.
I read a lot about bounded context, it seems to me that this is the most delicate approach in all this, and maybe the most difficult thing to explain and to apply in a real project.
Fortunately, my domain here is very simple ;-)
I try to identify the different bounded contexts and to determine which model becomes the aggregate root in each of these contexts.
The domain rules are really simple:
When a writer composes a blog post he MUST choose a category to save his post in, and he optionally can select multiple tags for improving his post visibility
When a reader visits the Blog, he can browse blog posts by category or by tags
With only these rules, we already get several bounded contexts, am I right ?
User (writer) composes a post context. In these context, the Post is the aggregate root
User (reader) browses posts by category. In these context, the Category is the aggregate root.
User (reader) browses posts by tags. In this context, well, I'm not sure... ;-)
Am I thinking things right ?
Given I am (right), I wonder, in the implementation of this, who is responsible of creating the different objects and relationships ?
Take the context where an user composes a new blog post for instance, I really don't have any clue about where I should create tags instances and whether or not I should create a relationship between the Post and its tags in the write model. The same goes with the Category, no idea :p
Also, does a bounded context means a specific model ? Meaning that for each bounded context I would have a different object graph (in write model) ?
Need some brain wave to see this clear in my mind ;-)
For adding a new post, so far, my controller asks the command bus to handle a "ComposeCommand", the handler (PostService) creates a new "Post" instance, invokes a compose method on it and finally asks the write persistence to save the new Post.
The Post::compose() method raises a "PostComposedEvent" event which the read model listens to update its data.
In all this I don't know how to introduce "Category" and "Tags".
Thanks.