Uniqueness validation when using CQRS and Event sourcing

后端 未结 3 1531
渐次进展
渐次进展 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:04

    I would go for an application service that is just responsible for generating unique ShortURL's. You can use a transactional DB to implement this behaviour. Typically this service would be used by the command handling part of the BlogPost aggregate. If there is a duplicate ShortURL, you can fire a DuplicateUrlErrorEvent. You can pre-catch this in the UI (but never 100%) by creating a thin query-model using the same data-source, so you can query whether a shortified URL is unique before submitting the post (as described by @RyanR's answer).

提交回复
热议问题