Should I use a command side projection or query aggregates directly within interceptors when validating state outside a single aggregate?

Hello all,

This question is somewhat of a followup from a previous one that I had regarding command interceptors that can be found here.

I’ve seen in other posts mentions of using an entity manager to be able to query against aggregates. This made me wonder if it was necessary for me to be creating command side projections when validating a command in an interceptor when there is context required outside the scope of a single aggregate.

Using the example I had in the post linked above, I need to know that there is an account, and a business, before creating a loyalty bank. Is there a way that I could just query the aggregates directly from within the interceptor? If so, what are the disadvantages if any?

I initially went with the notion of “command projections” based on some other posts and a podcast that I listened to, and am overall happy with the results. But if there is a way to do this directly with the aggregates I don’t see why the projections would be needed.

Thanks for you time!

Hi,

It sounds like your current solution is a lot better than any of the suggestions here. Using a projection to validate whether certain values are unique is probably the best way to go.

Imagine you would query the aggregate’s state. Besides the fact that you now have to structure the aggregate to do both validation and data retrieval, would you even be able to identify which aggregates to load?

Loading aggregates will definitely be slower than loading a subset of data in a built-for-purpose projection.

In Axon 5, where we will have Dynamic Consistency Boundary (DBC) support, this can be modeled differently altogether. In that case, you wouldn’t need the projection anymore. Coming soon™