CommandGateway - Send command from query event handler - bad practice?

Hello everyone!

Here is my question:
I have a libs component that encapsulate every domain aspect of my application. On another component, a monolithic app (with query handlers inside) that updates views and expose API’s.

My domain doesn’t have logic to handle with a specific external API (Identity), but need to store some information regarding events from the external API.
Below I’ll add my Handler (inside query side) and the aggregate that it deals with (on domain side).

I have achieved my goal, but the fact that I’m sending a command from a QueryHandler makes me think that the design is wrong.

Thanks!

Screen Shot 2019-05-22 at 10.23.43.png

My thoughts on this is that instead of having EventHandlers raise commands, could you just have your initial command handler raise both events?

So for example when you are handling the CreateUserCommand, could that command handler raise both events?

This makes concepts such as event replay easier to reason about.

-Ben

The other bonus (that I forgot) is that it encapsulates your logic into the aggregate. This keeps you logic more centralized vs spread out across your application.

-Ben

Hello Ben! Thanks for your answer.

The main reason that I have not added to my aggregate is because the command will be handled only after a API integration.
I do not want to add a port inside my aggregate. My command will be handled only if my Identity Server creates my user (for example).

Thanks and regards,
Gertel

Sorry, I missed that part of your explanation. In the case of integrating with an external API raising commands from a handler works fine.

You could always try a saga instead of an EventHandler.

-Ben