using custom CommandTargetResolver in fixtures

Hi,

In order to use a custom command target resolver during tests i came up with this:

`

fixture = Fixtures.newGivenWhenThenFixture(BusinessDomainAR.class);
AggregateAnnotationCommandHandler aggregateAnnotationCommandHandler =
new AggregateAnnotationCommandHandler(BusinessDomainAR.class, fixture.getRepository(),
new CustomCommandTargetResolver.ForBusinessDomain());
fixture.registerCommandHandler(AddAdministrator.class, aggregateAnnotationCommandHandler);
fixture.registerCommandHandler(RemoveAdministrator.class, aggregateAnnotationCommandHandler);
// register all other command classes used in the AR

`

Is there a way that allows me to do this without registering each command class individually ?

Thanks,
Jorg

Hi Jorg,

you can do:
aggregateAnnotationCommandHandler.subscribe(CommandBus) to automatically subscribe all supported commands to the Command Bus.

Cheers,

Allard

Hi Allard,

There is no such method on the commandhandler, only a deprecated subscribe() method. I’m still on 2.4.6 maybe that’s why. I made it a bit more convenient for my case using some classpath scanning and reflection, it’s ok like that.

Jorg

Ah 2.4.6. That explains why the method doesn’t exist.

In that case, you have the supportedCommands() method on the AggregateAnnotationCommandHandler. For each entry there, subscribe the AggregateAnnotationCommandHandler to the command bus. Something like:
AggregateAnnotationCommandHandler.supportedCommands().forEach(c -> commandBus.subscribe(c, this));

Cheers,

Allard