Denormalizers CQRS / ES

I am working on a web billing application that uses an event source and CQRS.

I have two denormalizers for different requests (one for a list of invoice summaries and one for a single invoice with full details). It seems strange to me that I need to copy a lot of logic for these two denormalizers - for example, listen to events that change the grand total, subtotal, taxes, etc.

I ended up passing the aggregate itself, which contains the real calculated data, on the messaging bus, not just events, and denormalizers were handled instead.

This made it easier for me, but it seems to be different from the pattern. This approach hasn't been mentioned in any of the articles I've read.

I liked the idea of ​​just skipping the events on the bus, and each denormalizer responded to what it needed, but in practice it became more cumbersome.

I'd love to hear what you think.

Thank you for your help!


source to share

1 answer

As suggested by guillaume31 in the comment above, you can simply enrich your domain model with special events like NewTotalComputed

. Depending on the number of events, however, this may soon clutter up your domain model.

Alternatively, you can refactor the computation logic into a special strategy class that is used from both the domain model (aggregate root) and the read model.



All Articles