Axon 3.0M5 Repositories and AggregateFactory

Hello,

after the M5 release, I tried to migrate to @EnableAxon to get rid of the majority of the manual configuration.

I stumbled across the following issues:

When trying to:

@Autowire Repository<SomeAggregate> repository;

It is not available. What I understood is, that it would be made available automatically. How would I inject it ?

When I add a manual configuration:

`
@Bean
public Repository agentEventSourcingRepository() {
return new EventSourcingRepository<>(new SomeAggregateAggregateFactory(), eventStore);
}

`

The above injection works just fine.

However, even though, I can now inject the repository into a command handler service, it appears to forget the AggregateFactory I have wired in in the above configuration.

What I have is a class hierarchy for implementing the Aggregate, and I have a command handler for creating the different sub-classes depending on the creation command. And thus, I also need the Aggregate factory for recreating the aggregates.

What is the recommended way to wire this up using the @EnableAxon feature ?

And how do I inject the repository when not defining it manually ?

My manual configuration from M4 works just fine with M5

Thank you.

Best regatds,
Dominic

Hi Dominic,

in your @Aggreagte annotation, you can add a reference to the Repository bean to use to load that aggregate. If you don’t specify it, Axon will create its own repository.
Since information from Generic parameters isn’t used (in many cases) to resolve beans, Spring doesn’t always recognize the Repository instance as already defined.

The repository that Axon uses, isn’t made available as a Spring bean by default. So if you need to inject the repository, you’ll have to define it yourself. For now… :wink:

Cheers,

Allard

That makes sense. I tried it and it works like a charm. Now I was able to dump a lot of boilerplate configuration files for the different aggregates, event handlers, and sagas.

Thanks, Allard.

Best regards,
Dominic