Is it possible to inject another Non Saga repository in Axon Saga Implementation

Hi,

I am working on a saga implementation where along with Saga repository I need to persist the data into another repository. During EventCreate I am able to have the data saved in my repository along with Saga Repository. When I fire the EventClosed event with the same userId the second method get invoked but my repository is null. As per the Axon doc and other queries I can understand that I need to inject the resources however is it possible to inject some thing which is not related to Saga.

public class UserSaga extends AbstractAnnotatedSaga {
private String userId;

Private transient Repository repository;

@StartSaga
@SagaEventHandler(associationProperty = “userId”)
public void handle(final EventCreate event) {
// Repository is automatically injected
repository.save(…);
}

@SagaEventHandler(associationProperty = “userId”)
public void handle(final EventClosed event) {

repository.save(…)
}

Hi,

please make sure, that you remember about setter. As you can find here http://www.axonframework.org/docs/2.0/sagas.html 7.1.4, all fields which are injected by ResourceInjector are injected by setters. Please check it and if everything is ok and still not working please show me your config file (with beans).

Hi,

I tried the suggestions you have made but still getting repository as null in the below method,

@SagaEventHandler(associationProperty = “userId”)
public void handle(final EventClosed event) {

repository.save(…)
}

As suggested please find below the config file I am using.

<axon:saga-manager id=“sagaManager” saga-repository=“sagaRepository” event-bus=“eventBus”>
axon:types
com.test.UserSaga
</axon:types>
</axon:saga-manager>

Let me know anything was missing in the configuration file so I can have the repository object in the second method of UserSaga.Appreciate your help.

It seems you’ve created your own SagaRepository implementation. Are you sure the injector is used to inject the Saga’s resources?
The SpringResourceInjector uses Spring’s injection mechanism. So you don’t need setters per se, may also be fields. Make sure that whatever you need to inject is annotated with @Autowired or @Inject.

Cheers,

Allard

Hi Allard,

I was able to inject the additional repositories in my SagaRepository implementation using the SpringResourceInjector and now able use them using @Autowired.

Many Thanks.