Pergunta

I'm getting started with CQRS and I'm finding that my Event class definitions match my Command definitions almost 1 to 1. Aside from the obvious code repetition, I'm trying to figure out what I'm doing wrong. There are certainly some cases where the events don't match the commands....but not many.

Take the simple CUD scenario:

Command Classes:

  • CreatePost
  • UpdatePost
  • DeletePost

Event Classes:

  • CreatedPost
  • UpdatedPost
  • DeletedPost

Any advice on this?

I'm using an event store, if that makes any difference.

Thanks.

Foi útil?

Solução

You wouldn't normally use CQRS for CRUD scenarios. There are way simpler tools and patterns to create CRUDy applications.

CQRS brings many advantages to behavior-rich scenarios, where the verbs are not Create, Read, Update, Delete, but rather resemble real behavior. Like PromoteEmployee or BlacklistVendor.

Once you start modelling a behavior-rich domain, there might still be many corelating commands/events - which isn't a bad thing -, but you will also find that commands and the resulting events can be very different both in size (data contained) and in numbers.

Outras dicas

To add a little to Dennis Traub's answer, CQRS extends past how you structure your code into the realm of the specs, namely how the UI works. Point being not all UI's are CQRS-friendly; you want something more along the lines of Task-based-UI's rather than CRUD-y UI's.

Start with CRUD-y UI's and you may find yourself frustrated when applying CQRS.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top