SagaTestFixture resource injection

Hi,

In Axon 2 i used to inject parameters in @SagaEventHandlers methods, for example:

@SagaEventHandler(associationProperty = “someId”)
public void onSomethingHappened(SomethingHappened event, Service service) {
service.call(…);

// other stuff
}

Using Axon 3 i cannot get this to work in my SagaTestFixture:

fixture = new SagaTestFixture<>(TestSaga.class);
fixture.registerResource(service);

When running the test, it will complain that the resource is not registered.

If i use a private transient field with a setter annotated with @Inject it will inject the service just fine, but i would prefer to use ‘old’ way of passing my resources. This also prevents me from having to include the inject jar, since i’m using springg’s @Autowired for everything else.

I’m using the same approach for aggregates and those tests can find the resources just fine (without the private fields with setter).

Can the same be done for sagas?

Greets Rolf

Hi Rolf,

I’ve just checked this, and it seems like a “missing feature” in the SagaTestFixture and there doesn’t seem to be an easy workaround for it. I will schedule a fix for the 3.0.1 release.

Cheers,

Allard

Hey Allard,

Thanks for your answer :slight_smile:

I’ve noticed the ParameterResolverFactory mechanic for Sagas have been replaced with the ResourceInjector, which injects the resources when creating or loading the saga. So i guess the missing feature is not limited to the SagaTestFixture but for Sagas in general.

If the preferred way is not resolving parameters of the @SagaEventHandler methods but just private transient fields i can live with that, but i really liked this unified way of injecting components into Aggregates and Saga’s :slight_smile:

Anyway thanks again, looking forward to 3.0.1!

Greets Rolf