MessageHandlers and Repositories

Hi,

Is it possible to autowire the default created repository for an aggregate in a MessageHandlerInterceptor? My axon version is 4.7.3.

Can RepositoryProvider be used to fetch the repository for a specific aggregate?

If you’re in Spring, and as of Axon Framework 4.7, you can just autowire Repository<MyAggregate> into any (Spring) component. So you can wire your MessageHandlerInterceptor with the repository.

Whether you really want/need to do that is another thing. I’d say wiring a Repository would raise a little red flag or at least an eyebrow.

You can also use the Configuration (from org.axonframework.config package) to obtain a repository for an aggregate:

configuration.aggregateConfiguration(MyAggregate.class).repository()

Hope this helps.