Closed kolipka closed 5 years ago
Hi.
As long as you keep everything synchronous it doesn't matter that much, but querying the read model is probably the simplest.
A good idea would be to query the read side either from the client before sending the command as well as do a check in the command handler. If you search for CQRS and uniqueness, you will find a lot of discussion around this, and you will see that there is no clear answer. But as long as everything is synchronous my suggestion is to keep it simple and query the read model. In an asynchronous context you will need to store the ProjectCodes in another aggregate or some place you can query and save in the same transaction. If this is not possible there are other more complex ways as well, involving compensating actions or other techniques.
Thank you! Awesome work btw!
I have
Project
aggregate withProjectCode
property provided by User. I must ensure that it is unique among all projects. Should I do it in CommandHandler using Query to ReadModel? Or should I createAllProjects
aggregate that will hold list of project codes and throw on CreateProjectCommand attempt?