Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injection in CommandHandler does not work with javax.inject.Provider #1068

Open
nils-christian opened this issue Apr 24, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@nils-christian
Copy link

commented Apr 24, 2019

Hi,

Our project is a Spring Boot application with hierarchical Spring contexts which depend on each other. As this creates cycles in some few cases, we let Spring inject providers for the dependencies instead of the dependencies directly. For this purpose we use the JSR330 provider interface.

This works fine in Spring beans, but not with Axon command handlers. Let's ignore the hierarchical context and assume we have a bean OrderService in our context. The following would work:

@Component
public class CreateOrderCommandHandler {

	public CreateOrderCommandHandler( final Provider<OrderService> service ) {
		...
	}

	@CommandHandler
	public void on( final CreateOrderCommand command ) {
		...
	}

}

The same goes for the following:

@Component
public class CreateOrderCommandHandler {

	@CommandHandler
	public void on( final CreateOrderCommand command, final OrderService service ) {
		 ...
	}

}

But the following won't work:

@Component
public class CreateOrderCommandHandler {

	@CommandHandler
	public void on( final CreateOrderCommand command, final Provider<OrderService> service ) {
		 ...
	}

}

It results in

Unable to resolve parameter 1 (Provider) in handler

I would assume that the injection of a provider would work as well. If needed I can upload a minimal working example for the whole issue (without hierarchical contexts).

As our case is actually an aggregate and the command handler is the constructor we don't have the possibility to provide the dependencies in another way.

Thank you and best regards

Nils

@abuijze

This comment has been minimized.

Copy link
Member

commented Apr 24, 2019

Hi Nils,

the support for injecting Spring beans in @CommandHandler annotated methods should not be considered a full-fledged JSR330 implementation. The Provider interface is not supported as a parameter value, at the moment. If you wish to use the OrderService inside a Command Handler, you should inject it as such (thus without the Provider).

If you know of an easy way to change the SpringBeanParameterResolver to support this, then I'd love to hear that.

Allard

@nils-christian

This comment has been minimized.

Copy link
Author

commented Apr 24, 2019

Hi Allard,

I see. Thank you for your feedback. I will take a closer look at the mentioned resolver class.

Best regards

Nils

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.