Also posted on Stack Overflow <http://stackoverflow.com/q/7111518/403455>

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<http://stackoverflow.com/questions/1221920/getting-multiple-guice-singletons-of-the-same-type/1407719#1407719>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.

-- 
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/-/EvibDiIZ_wcJ.
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.

Reply via email to