Producing an AxonDBEventStore with AxonFramework CDI

Hi,

I was wondering if anyone has already been able to produce an AxonDBEventStore with AxonFramework CDI.
At the moment I have the following producer:

@Produces
@Singleton
public EventBus eventStore(AxonDBConfiguration axonDBConfiguration, Serializer serializer, @Any Instance upcasters)
{
EventUpcasterChain eventUpcasterChain = new EventUpcasterChain(Streams.stream(upcasters.iterator()).collect(Collectors.toList()));
AxonDBEventStore axonDBEventStore = new AxonDBEventStore(axonDBConfiguration, serializer, eventUpcasterChain);
axonDBEventStore.registerDispatchInterceptor(new AddSourceDispatchInterceptorImpl());
return axonDBEventStore;
}

But changing the return type to AxonDBEventStore gives the following error:

org.jboss.weld.exceptions.DeploymentException: WELD-001409: Ambiguous dependencies for type EventBus with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject private com.brutex.health.AxonDBTrackingProcessorHealthCheck.eventBus
at com.brutex.health.AxonDBTrackingProcessorHealthCheck.eventBus(AxonDBTrackingProcessorHealthCheck.java:0)
Possible dependencies:

  • org.axonframework.cdi.BeanWrapper@174e5016,
  • Producer Method [AxonDBEventStore] with qualifiers [@Any @Default] declared as [[BackedAnnotatedMethod] @Produces @Singleton public com.brutex.axon.AxonConfiguration.eventStore(AxonDBConfiguration, Serializer, @Any Instance)]

I don’t understand why it’s perfectly fine to produce an EventBus but producing an AxonDBEventStore leads to ambiguous dependencies. Can anyone shed some light on this?

Regards,
Jens

Hi Jens,

the CDI module is still in alpha phase. My hunch is that either the cdi module, or cdi itself isn’t flexible enough, in this case.
The CDI module has a listener of a ProcessProducer<T, EventBus>, which according to the documentation is reports producers that declare a returntype of EventBus. It is unclear to me whether that would mean a producer of a subtype should also be included. Given your issue, I guess it doesn’t.

So I’m afraid that with the current state of the CDI module, you’d need to declare a @Producer of EventBus.

Kind regards,

Allard