I have made a external commandhandler class besides the Aggregate.
When i handle a command in this command handler after a command handled in the aggregate i get ‘Cannot retrieve current AggregateLifecycle; none is yet defined’ . The command is dispatched with a CommandGateway .
It is also reproducable in a unit test with a Aggregatefixture :
@Before
public void setUp() {
fixture = new AggregateTestFixture<>(DossierAggregate.class);
fixture.registerInjectableResource(new DefaultCommandGateway(fixture.getCommandBus()));
fixture.registerAnnotatedCommandHandler(new KikCommandHandler());
}
@Test
public void als_een_kikakte_toegevoegd_wordt_dan_worden_er_events_weggeschreven() {
StukId stukId = new TIAStukId("NL.IMKAD.TIAStuk.123456789");
DossierAanmakenMetStukId stukIdAanbieden = new DossierAanmakenMetStukId(stukId.getId());
Stuk stuk = new TIAStuk("4", "12345", "123");
KikAkteOpslaan kikAkteOpslaan = new KikAkteOpslaan(new KikAkte(dossierId, stuk));
fixture
.givenCommands(stukIdAanbieden)
.when(kikAkteOpslaan)
.expectEvents(new TerInschrijvingAangebodenStukAangeboden(dossierId,
new DeelEnNummer("12345", "123"),
false,
null));
}
I have added a jar with the domain events and commands (simplified and all dependent code in one package)
Gerlo Hesselink
axon_external_commandhandler.zip (90.3 KB)