Skip to content

Commit

Permalink
Merge pull request #2 from koenverwimp/pickup-resource-injector
Browse files Browse the repository at this point in the history
Pick-up ResourceInjector producer during 'autoconfig'
  • Loading branch information
Bert Laverman authored Jul 25, 2019
2 parents de3c316 + a17f8f3 commit be6dbe1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cdi/src/main/java/org/axonframework/cdi/AxonCdiExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,6 +86,7 @@ public class AxonCdiExtension implements Extension {
private Producer<DeadlineManager> deadlineManagerProducer;
private Producer<EventProcessingModule> eventProcessingModuleProducer;
private Producer<EventProcessingConfiguration> eventProcessingConfigurationProducer;
private Producer<ResourceInjector> resourceInjectorProducer;

// Mark: Many of the beans and producers I am processing may use
// container resources such as entity managers, etc. I believe this means
Expand Down Expand Up @@ -448,6 +450,14 @@ <T> void processEventUpcasterProducer(
this.eventUpcasterProducers.add(processProducer.getProducer());
}

<T> void resourceInjectorProducer(
@Observes final ProcessProducer<T, ResourceInjector> processProducer) {

logger.debug("Producer for resource injector found: {}.", processProducer.getProducer());

this.resourceInjectorProducer = processProducer.getProducer();
}

/**
* Scans all beans and collects beans with message handlers.
*
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit be6dbe1

Please sign in to comment.