Uniqueness validation when using CQRS and Event sourcing

后端 未结 3 1537
渐次进展
渐次进展 2021-01-31 10:42

I\'m trying to implement my own CQRS infrastructure with Event Sourcing to learn it better. As a sample project I\'m implementing a blog engine, I know it might not be a perfect

3条回答
  •  庸人自扰
    2021-01-31 11:01

    It depends what 'the business' wants to happen. If you want the client (creator of the commands) to be responsible for choosing a short URL, it should have a read store that it verifies the uniqueness of it from. When the user types in a short URL, the view should check that the short URL is unique and present a validation error if it is not. Whenever a post is saved, an event will publish the updated info (including the short URL) which keeps the read store in sync.

提交回复
热议问题