In CQRS, if a saga (or more precisely a process manager according to the CQRS Journey book) sends out a new command to change aggregates how can I ensure that this command is not possible to send from anywhere else (e.g. by a programmer on UI part). That is the command is only for "internal" usage of the saga?

How to handle a situation, where the command is "private" for the saga only.

I am writing an app in Java with Axon framework. But this can be related to any implementation (even in C#).

I came up with only one solution - store the command class file in saga's package and make the class's constructor package-private. Thus only saga can instantiate the command. I cannot make the whole class private because it must be visible from aggregate's command handlers.

Is there any better way?

  • 2
    This is better handled by authorization. Only authorize the user account which runs the saga to run this command. – Kasey Speakman Nov 7 '15 at 20:59
  • Not sure if I follow. The command is saga's internal way of communicating with aggregates. I merely want to disable commandGateway.send(new ThatCommand) from anywhere but the saga. Just so no other programmer would use it to do some "illegal" stuff outside the saga. – redhead Nov 7 '15 at 21:07
  • Then maybe talk to the other programmers and tell them. Also in most languages there are language constructs that allow classes to be package/module only, so you might just want to use the appropriate language features. – Alexander Langer Nov 8 '15 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.