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(SingletonClass.class).annotatedWith(B.class).to(SingletonClass.class).in(Singleton.class);
Do I have to create a provider class and expose the constructor of OneOfEachAnnotation just to accomplish this? I'll be very surprised if there isn't a simpler method for solving this common problem.
bind(OneOfEachAnnotation.class).annotatedWith(A.class).to(OneOfEachAnnotation.class).in(Singleton.class);
bind(OneOfEachAnnotation.class).annotatedWith(B.class).to(OneOfEachAnnotation.class).in(Singleton.class);
To view this discussion on the web visit https://groups.google.com/d/msg/google-guice/-/XrKCkJP9QVEJ.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to google...@googlegroups.com.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
Thanks for pointing this out Sam. The code in my question does have the @Singleton annotation on the OneOfEachAnnotation. Removing this fixed the problem.
It's not entirely clear to me why this causes it to behave as a "single" singleton instead of respecting the annotation. If you are able to help me understand why, I'd be grateful.
--
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/-/vGTbS-WhFEUJ.
--
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/-/wEXSWcM1hI4J.