Aggregate aggregateAnnotation = beanFactory.findAnnotationOnBean(aggregate, Aggregate.class); Class<A> aggregateType = (Class<A>) beanFactory.getType(aggregate); AggregateConfigurer<A> aggregateConf = AggregateConfigurer.defaultConfiguration(aggregateType); if ("".equals(aggregateAnnotation.repository())) { String repositoryName = lcFirst(aggregateType.getSimpleName()) + "Repository"; aggregate.substring(0, 1).toLowerCase() + aggregate.substring(1) + "AggregateFactory"; if (beanFactory.containsBean(repositoryName)) { aggregateConf.configureRepository(c -> beanFactory.getBean(repositoryName, Repository.class)); } else { registry.registerBeanDefinition(repositoryName, .configureAggregateFactory(c -> beanFactory.getBean(factoryName, AggregateFactory.class)); String triggerDefinition = aggregateAnnotation.snapshotTriggerDefinition(); if (!"".equals(triggerDefinition)) { aggregateConf.configureSnapshotTrigger( c -> beanFactory.getBean(triggerDefinition, SnapshotTriggerDefinition.class)); aggregateConf.configureRepository( c -> GenericJpaRepository.builder(aggregateType) .parameterResolverFactory(c.parameterResolverFactory()) aggregateConf.configureRepository( c -> beanFactory.getBean(aggregateAnnotation.repository(), Repository.class)); aggregateConf.configureCommandTargetResolver(c -> getBean(aggregateAnnotation.commandTargetResolver(), c)); } else { findComponent(CommandTargetResolver.class).ifPresent(commandTargetResolver -> aggregateConf
/** * Creates a Configuration for an aggregate of given {@code aggregateType}, which is mapped to a relational * database using an EntityManager provided by given {@code entityManagerProvider}. The given {@code aggregateType} * is expected to be a proper JPA Entity. * * @param aggregateType The type of Aggregate to configure * @param entityManagerProvider The provider for Axon to retrieve the EntityManager from * @param <A> The type of Aggregate to configure * @return An AggregateConfigurer instance for further configuration of the Aggregate */ public static <A> AggregateConfigurer<A> jpaMappedConfiguration(Class<A> aggregateType, EntityManagerProvider entityManagerProvider) { AggregateConfigurer<A> configurer = new AggregateConfigurer<>(aggregateType); return configurer.configureRepository( c -> GenericJpaRepository.builder(aggregateType) .aggregateModel(configurer.metaModel.get()) .entityManagerProvider(entityManagerProvider) .eventBus(c.eventBus()) .repositoryProvider(c::repository) .build() ); }
/** * Configures an Aggregate using default settings. This means the aggregate is expected to be Event Sourced if an * Event Store present in the configuration. Otherwise, an explicit repository must be configured and the * {@link #configureAggregate(AggregateConfiguration)} must be used to register the aggregate. * * @param aggregate The aggregate type to register with the Configuration * @param <A> The type of aggregate * @return the current instance of the Configurer, for chaining purposes */ default <A> Configurer configureAggregate(Class<A> aggregate) { return configureAggregate(AggregateConfigurer.defaultConfiguration(aggregate)); }
@Before public void setUp() { configuration = DefaultConfigurer.defaultConfiguration() .configureEmbeddedEventStore(c -> new InMemoryEventStorageEngine()) .configureAggregate(AggregateConfigurer.defaultConfiguration(MyAggregate.class) .configureAggregateFactory(c -> new AggregateFactory<MyAggregate>() { @Override public MyAggregate createAggregateRoot(String aggregateIdentifier, DomainEventMessage<?> firstEvent) { return new MyAggregate(aggregateIdentifier); } @Override public Class<MyAggregate> getAggregateType() { return MyAggregate.class; } })) .registerCommandHandler(c -> new MyCommandHandler(c.repository(MyAggregate.class), c.commandGateway())) .buildConfiguration(); configuration.start(); command = new MyCommand("outer", aggregateIdentifier, new MyCommand("middle", aggregateIdentifier, new MyCommand("inner", aggregateIdentifier))); }
/** * Creates a default Configuration for an aggregate of the given {@code aggregateType}. This required either a * Repository to be configured using {@link #configureRepository(Function)}, or that the Global Configuration * contains an Event Store and the Aggregate support Event Sourcing. * * @param aggregateType The type of Aggregate to configure * @param <A> The type of Aggregate to configure * @return An AggregateConfigurer instance for further configuration of the Aggregate */ public static <A> AggregateConfigurer<A> defaultConfiguration(Class<A> aggregateType) { return new AggregateConfigurer<>(aggregateType); }
c.handlerDefinition(aggregate)) ).createModel(aggregate)); commandTargetResolver = new Component<>(() -> parent, name("commandTargetResolver"), c -> c.getComponent(CommandTargetResolver.class, AnnotationCommandTargetResolver::new)); snapshotTriggerDefinition = new Component<>(() -> parent, name("snapshotTriggerDefinition"), c -> NoSnapshotTriggerDefinition.INSTANCE); aggregateFactory = new Component<>(() -> parent, name("aggregateFactory"), c -> new GenericAggregateFactory<>(aggregate)); repository = new Component<>( () -> parent,
/** * Configures an Aggregate using default settings. This means the aggregate is expected to be Event Sourced if an * Event Store present in the configuration. Otherwise, an explicit repository must be configured and the * {@link #configureAggregate(AggregateConfiguration)} must be used to register the aggregate. * * @param aggregate The aggregate type to register with the Configuration * @param <A> The type of aggregate * @return the current instance of the Configurer, for chaining purposes */ default <A> Configurer configureAggregate(Class<A> aggregate) { return configureAggregate(AggregateConfigurer.defaultConfiguration(aggregate)); }
/** * Creates a default Configuration for an aggregate of the given {@code aggregateType}. This required either a * Repository to be configured using {@link #configureRepository(Function)}, or that the Global Configuration * contains an Event Store and the Aggregate support Event Sourcing. * * @param aggregateType The type of Aggregate to configure * @param <A> The type of Aggregate to configure * @return An AggregateConfigurer instance for further configuration of the Aggregate */ public static <A> AggregateConfigurer<A> defaultConfiguration(Class<A> aggregateType) { return new AggregateConfigurer<>(aggregateType); }
c.handlerDefinition(aggregate))) .createModel(aggregate)); commandTargetResolver = new Component<>(() -> parent, name("commandTargetResolver"), c -> c.getComponent(CommandTargetResolver.class, AnnotationCommandTargetResolver::new)); snapshotTriggerDefinition = new Component<>(() -> parent, name("snapshotTriggerDefinition"), c -> NoSnapshotTriggerDefinition.INSTANCE); aggregateFactory = new Component<>(() -> parent, name("aggregateFactory"), c -> new GenericAggregateFactory<>(aggregate)); repository = new Component<>(() -> parent, "Repository<" + aggregate.getSimpleName() + ">", c -> { Assert.state(c.eventBus() instanceof EventStore,
AggregateConfigurer<A> configurer = new AggregateConfigurer<>(aggregateType); return configurer.configureRepository( c -> { EntityManagerProvider entityManagerProvider = c.getComponent(
/** * Configures an Aggregate using default settings. This means the aggregate is expected to be Event Sourced if an * Event Store present in the configuration. Otherwise, an explicit repository must be configured and the * {@link #configureAggregate(AggregateConfiguration)} must be used to register the aggregate. * * @param aggregate The aggregate type to register with the Configuration * @param <A> The type of aggregate * @return the current instance of the Configurer, for chaining purposes */ default <A> Configurer configureAggregate(Class<A> aggregate) { return configureAggregate(AggregateConfigurer.defaultConfiguration(aggregate)); }
/** * Creates a default Configuration for an aggregate of the given {@code aggregateType}. This required either a * Repository to be configured using {@link #configureRepository(Function)}, or that the Global Configuration * contains an Event Store and the Aggregate support Event Sourcing. * * @param aggregateType The type of Aggregate to configure * @param <A> The type of Aggregate to configure * @return An AggregateConfigurer instance for further configuration of the Aggregate */ public static <A> AggregateConfigurer<A> defaultConfiguration(Class<A> aggregateType) { return new AggregateConfigurer<>(aggregateType); }
c.handlerDefinition(aggregate)) ).createModel(aggregate)); commandTargetResolver = new Component<>(() -> parent, name("commandTargetResolver"), c -> c.getComponent(CommandTargetResolver.class, AnnotationCommandTargetResolver::new)); snapshotTriggerDefinition = new Component<>(() -> parent, name("snapshotTriggerDefinition"), c -> NoSnapshotTriggerDefinition.INSTANCE); aggregateFactory = new Component<>(() -> parent, name("aggregateFactory"), c -> new GenericAggregateFactory<>(aggregate)); repository = new Component<>( () -> parent,
/** * Creates a Configuration for an aggregate of given {@code aggregateType}, which is mapped to a relational * database using an EntityManager provided by given {@code entityManagerProvider}. The given {@code aggregateType} * is expected to be a proper JPA Entity. * * @param aggregateType The type of Aggregate to configure * @param entityManagerProvider The provider for Axon to retrieve the EntityManager from * @param <A> The type of Aggregate to configure * @return An AggregateConfigurer instance for further configuration of the Aggregate */ public static <A> AggregateConfigurer<A> jpaMappedConfiguration(Class<A> aggregateType, EntityManagerProvider entityManagerProvider) { AggregateConfigurer<A> configurer = new AggregateConfigurer<>(aggregateType); return configurer.configureRepository( c -> new GenericJpaRepository<>(entityManagerProvider, configurer.metaModel.get(), c.eventBus(), (RepositoryProvider) c::repository)); }
/** * Creates a Configuration for an aggregate of given {@code aggregateType}, which is mapped to a relational * database using an EntityManager obtained from the main configuration. The given {@code aggregateType} * is expected to be a proper JPA Entity. * <p> * The EntityManagerProvider is expected to have been registered with the Configurer (which would be the case when * using {@link DefaultConfigurer#jpaConfiguration(EntityManagerProvider)}. If that is not the case, consider using * {@link #jpaMappedConfiguration(Class, EntityManagerProvider)} instead. * * @param aggregateType The type of Aggregate to configure * @param <A> The type of Aggregate to configure * @return An AggregateConfigurer instance for further configuration of the Aggregate */ public static <A> AggregateConfigurer<A> jpaMappedConfiguration(Class<A> aggregateType) { AggregateConfigurer<A> configurer = new AggregateConfigurer<>(aggregateType); return configurer.configureRepository( c -> new GenericJpaRepository<>(c.getComponent(EntityManagerProvider.class, () -> { throw new AxonConfigurationException(format( "JPA has not been correctly configured for aggregate [%s]. Either provide an EntityManagerProvider, or use DefaultConfigurer.jpaConfiguration(...) to define one for the entire configuration.", aggregateType.getSimpleName())); }), configurer.metaModel.get(), c.eventBus(), (RepositoryProvider) c::repository)); }
/** * Creates a Configuration for an aggregate of given {@code aggregateType}, which is mapped to a relational * database using an EntityManager provided by given {@code entityManagerProvider}. The given {@code aggregateType} * is expected to be a proper JPA Entity. * * @param aggregateType The type of Aggregate to configure * @param entityManagerProvider The provider for Axon to retrieve the EntityManager from * @param <A> The type of Aggregate to configure * @return An AggregateConfigurer instance for further configuration of the Aggregate */ public static <A> AggregateConfigurer<A> jpaMappedConfiguration(Class<A> aggregateType, EntityManagerProvider entityManagerProvider) { AggregateConfigurer<A> configurer = new AggregateConfigurer<>(aggregateType); return configurer.configureRepository( c -> GenericJpaRepository.builder(aggregateType) .aggregateModel(configurer.metaModel.get()) .entityManagerProvider(entityManagerProvider) .eventBus(c.eventBus()) .repositoryProvider(c::repository) .build() ); }
AggregateConfigurer<A> configurer = new AggregateConfigurer<>(aggregateType); return configurer.configureRepository( c -> { EntityManagerProvider entityManagerProvider = c.getComponent(