Eduard Rappa
Eduard Rappa

Reputation: 23

Guice dependency issue

I have some DAO class with 2 injected named instances:

@Inject
@Named("Name1")
DSLContext dsl1;

@Inject
@Named("Name2")
DSLContext dsl2; 

and everything works fine. At the same time I want to use different class which has injected (not named) DSLContext in it's constructor:

DSLContext dslContext;

@Inject
CommonsPlayerTokensDaoImpl(DSLContext dslContext) {
    this.dslContext = dslContext;
}

and I want to use one of my existing contexts here. Of course, in this case Guice cannot automatically resolve the dependency. How can I do it ?

Thanks, Ed

Upvotes: 0

Views: 86

Answers (1)

Andrei Koch
Andrei Koch

Reputation: 1140

You can use @Named annotation with constructor's parameter:
@Inject CommonsPlayerTokensDaoImpl(@Named("Name1") DSLContext dslContext) {

Upvotes: 1

Related Questions