EventStore doesn't get injected into a command handler of an aggregate

Hi there,

I’ve stumbled on a problem with Axon. I have a CommandHandler on an aggregate that receives two the parameters. The first parameter, obviously is the command, and the second parameter is an EventStore. So the signature basically looks like this:

`

@CommandHandler
public void handle(AssignRight command, EventStore eventStore) {
}

`

I’m using this in a unit test with a default configuration like this:

`

EventStorageEngine eventStorageEngine = new InMemoryEventStorageEngine();

Configuration configuration = DefaultConfigurer
.defaultConfiguration()
.configureEmbeddedEventStore(config -> eventStorageEngine)
.configureAggregate(Role.class)
.buildConfiguration();

configuration.start();

`

When I now send a command to the aggregate with this:

`

configuration.commandGateway().sendAndWait(
assignRight
);

`

I get the following exception:

`
org.axonframework.test.FixtureExecutionException: No resource of type [org.axonframework.eventsourcing.eventstore.EventStore] has been registered. It is required for one of the handlers being executed.

at org.axonframework.test.FixtureResourceParameterResolverFactory$FailingParameterResolver.resolveParameterValue(FixtureResourceParameterResolverFactory.java:58)
at org.axonframework.messaging.annotation.AnnotatedMessageHandlingMember.resolveParameterValues(AnnotatedMessageHandlingMember.java:151)
at org.axonframework.messaging.annotation.AnnotatedMessageHandlingMember.handle(AnnotatedMessageHandlingMember.java:127)
at org.axonframework.messaging.annotation.WrappedMessageHandlingMember.handle(WrappedMessageHandlingMember.java:61)
at org.axonframework.commandhandling.model.inspection.AnnotatedAggregate.lambda$handle$3(AnnotatedAggregate.java:220)
at org.axonframework.commandhandling.model.inspection.AnnotatedAggregate$$Lambda$150/1538399081.call(Unknown Source)
at org.axonframework.commandhandling.model.AggregateLifecycle.executeWithResult(AggregateLifecycle.java:167)
at org.axonframework.commandhandling.model.inspection.AnnotatedAggregate.handle(AnnotatedAggregate.java:218)
at org.axonframework.commandhandling.model.LockAwareAggregate.handle(LockAwareAggregate.java:82)

`

So obviously there is no EventStore registered in the resources list.

If I use the type EventBus for the second parameter, the parameter gets injected into the command handler. So did I miss some concept that forbids the use on an EventStore by an aggregates command handler? Or is this a bug?

Help’s appreciated.

Thanks in advance,

Frank.

Hi Frank,

you’ve hit an exception to the rule, I think. Some would call it a bug ;-).

The injection mechanism allows you to inject components that have been defined in the configuration. However, the EventStore is not registered in the configuration as an EventStore, but as EventBus (which then has an implementation that also implements Event Store). That’s why it only works when looking for the Event Bus.

I think a solution for this in Axon would be pretty simple, actually. And it does seem like a good idea to allow for the EventStore type to be injected as a parameter…

A workaround is pretty simple. Just call:
configurer.registerComponent(EventStore.class, Configuration::eventStore);

the eventStore() method on the configuration uses the EventBus type to retrieve the implementation, and checks whether it actually is an Event Store implementation.

Cheers,

Allard