CommandHandler and AR with list of entities

Hi,

I started using AbstractAnnotatedAggregateRoot and AbstractAnnotatedEntity

I noticed in the documentation that it is not possible to write

@CommandHandlingMember
private List list;

cfr section 3.3.3:

“Note that each command must have exactly one handler in the aggregate.This means that you cannot annotated multiple entities (either root nor not) with @CommandHandler, when they handle the same command type. This also means that it is not possible to annotate fields containing collections with @CommandHandlingMember.”

what is the best practice in this case?

  • place all commandhandlers in the AR
  • place all commandhandlers in a separate class outside the AR
  • create a MyEntityList class and place the Commandhandler on this member

any thoughts?

regards,

Chris

Hi Chris,

sorry for the late reply. Both internet access and time to respond were scarce.
The two options 1 and 3 you describe are exactly the options you have right now. Command handling on a collection of entities is one of the features in the pipeline.

The best option depends on the use case. If it’s only one or two commands, you can probably put the handler in the parent entity and delegate to one of the children. If the code becomes cluttered, you could create your own collection wrapper.

I wouldn’t go for the second option. Not that it’s a bad choice, but it a completely different style than the other two. I would only go for command handlers outside of the aggregate in special use cases. Consider it as a last resort.

Cheers,

Allard