I would like to bind a unique singleton instance for each annotation as shown below, such that Client1.a != Client1.b
and Client1.a == Client2.a
.
class X {}
@Singleton class OneOfEachAnnotation {
@Inject OneOfEachAnnotation(X x) { }
}
class Client1 {
@Inject Client(@A OneOfEachAnnotation a, @B OneOfEachAnnotation b) {}
}
class Client2 {
@Inject Client(@A OneOfEachAnnotation a, @B OneOfEachAnnotation b) {}
}
This answer seems to claim that I can accomplish the binding like this, but when I do so, Client1.a == Client1.b
.
bind(OneOfEachAnnotation.class).annotatedWith(A.class).to(OneOfEachAnnotation.class).in(Singleton.class);
bind(OneOfEachAnnotation.class).annotatedWith(B.class).to(OneOfEachAnnotation.class).in(Singleton.class);