*Also posted on stack overflow <http://stackoverflow.com/q/6708534/403455>*
I have a class A that holds a class B like this:
class A {
private final B;
@Inject
A(B b) {
this.b = b;
}
}
interface B {}
class B1 {}
class B2 {}
I'm using annotations to construct different flavors of A classes that each
hold the available B classes (@B1, @B2). The binding configurations look
like this:
@Provides @B1 A provideAwithB1(B1 b1) {
return new A(b1)
}
@Provides @B2 A provideAwithB2(B2 b2) {
return new A(b2)
}
Right now the only module configuration I can come up with prevents me from
making A's constructor private, and it seems more complex and verbose than
need be. Is there a Guice extension or technique that I am unaware of that
solves this problem more concisely? Ideally I'd write something like this
instead:
bindChildren(A.class).annotatedWith(B1annotation.class).to(B1.class);
bindChildren(A.class).annotatedWith(B2annotation.class).to(B2.class);
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-guice/-/DE3K51hdk_AJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.