Inject resources into SAGA

Hi all,

I would like to inject a non-Axon bean into my Saga.

If I’m correct, by default the ConfigurationResourceInject is used.

This can only inject components that are available in the DefaultConfigurer.

So I guess I have to call the “registerComponent” method on DefaultConfigurer.

What is the easiest way to get access to this object?

Kind regards,

Koen

Maybe provide my own ResourceInjector?

Hi Koen,

I am not completely sure what you’re referencing with ‘this object’ to be honest.
That can either be the entire Configurer or the ConfigurationResourceInjector at this moment.

Regardless, the simplest approach for you would likely be to use the Configurer#registerComponent(Class, Function<Configuration, ? extends C>) method to register additional components in to the Axon Configuration. As the default ResourceInjector in a non Spring environment (which I assume you’re in giving the nature of your question) is the ConfigurationResourceInjector, any resource you’d like to inject in your Saga instances will be retrieved from the Configuration that’s created out of the Configurer.

If you are in a Spring environment, you can simply wire the Configurer in an @Autowired method and register the components yourself.
If you are not in a Spring-env, I assume you are creating the Configurer yourself, so in that scenario you will already have access to it I think! :slight_smile:

Hope this helps you out Koen!

Cheers,
Steven

Hi Steven,

Thanks for your reply. Sorry for the confusing wordings in my first post.

In my case i am using Axon-CDI in a J2EE/CDI environment. I would like to inject some CDI/J2EE beans. I think this should work if i am able to get access to the default ConfigurationResourceInjector or provide my own ResourceInjector.

Are you sure Configurer is managed and can be injected?
It looks like the "public static Configurer defaultConfiguration()"is called, and eventually there is a concrete instantiation (new DefaultConfigurer…) not managed by the container.

So to be clear, I am not in a Spring environment but in AxonCDI. This has a similar “auto config” class, called AxonCDIExtension.

I think in my case we need some changes to the AxonCDI library so the AxonCDI should pick up my ResourceInjector provider so I can use the CdiResourceInjector.

Kind regards

Hi Koen,

Ah I get the predicament you’re in then.

If this is currently a missing feature in the Axon CDI Extension then I agree, this sounds like a feature request for that repository to me.

Would you be able to file such an issue on the repository, describing your current situation and what you think would be the approach forward?

Cheers,
Steven

I created an issue in the repository: https://github.com/AxonFramework/extension-cdi/issues/1.
If this issue can be validated, I can provide you a pull request if necessary.

Thanks in advance.