diff --git a/cdi/src/main/java/org/axonframework/cdi/AxonCdiExtension.java b/cdi/src/main/java/org/axonframework/cdi/AxonCdiExtension.java index cbc2b7d..ffef93f 100644 --- a/cdi/src/main/java/org/axonframework/cdi/AxonCdiExtension.java +++ b/cdi/src/main/java/org/axonframework/cdi/AxonCdiExtension.java @@ -19,6 +19,7 @@ import org.axonframework.modelling.command.CommandTargetResolver; import org.axonframework.modelling.command.GenericJpaRepository; import org.axonframework.modelling.command.Repository; +import org.axonframework.modelling.saga.ResourceInjector; import org.axonframework.modelling.saga.repository.SagaStore; import org.axonframework.queryhandling.QueryBus; import org.axonframework.queryhandling.QueryGateway; @@ -85,6 +86,7 @@ public class AxonCdiExtension implements Extension { private Producer deadlineManagerProducer; private Producer eventProcessingModuleProducer; private Producer eventProcessingConfigurationProducer; + private Producer resourceInjectorProducer; // Mark: Many of the beans and producers I am processing may use // container resources such as entity managers, etc. I believe this means @@ -448,6 +450,14 @@ void processEventUpcasterProducer( this.eventUpcasterProducers.add(processProducer.getProducer()); } + void resourceInjectorProducer( + @Observes final ProcessProducer processProducer) { + + logger.debug("Producer for resource injector found: {}.", processProducer.getProducer()); + + this.resourceInjectorProducer = processProducer.getProducer(); + } + /** * Scans all beans and collects beans with message handlers. * @@ -701,6 +711,14 @@ void afterBeanDiscovery(@Observes final AfterBeanDiscovery afterBeanDiscovery, configurer.configureEmbeddedEventStore(c -> eventStorageEngine); } + if (this.resourceInjectorProducer != null) { + ResourceInjector resourceInjector = produce(beanManager, resourceInjectorProducer); + + logger.info("Registering resource injector: {}.", resourceInjector.getClass().getSimpleName()); + + configurer.registerComponent(ResourceInjector.class, c -> resourceInjector); + } + // Now need to begin registering application components rather than // configuration components. registerAggregates(beanManager, configurer);