On Wednesday, 6 January 2016 15:19:34 UTC-5, [email protected] wrote:
>
>
> First question : does this actual create two instances or only one? Two I 
> guess and this is my first problem. How could I bind the same instance to 
> both types?
>

Yes, as written you'll have two separate singletons.  You want to bind 
server implementation *itself* as a singleton, like this:

bind(getServerClass()).in(Scopes.SINGLETON);

Second question :
>
> Would it be possible to ask the dev to define a *getServerType()* method, 
> that would return "*TheTypeTheDevWants*", in a way or another, so the 
> framework can use it to create the two bindings *by itself*? Something 
> like :
>
 
Yep, but it's not pretty :)

Type type = Types.newParameterizedType(IServer.class, getServerType());
TypeLiteral<?> typeLiteral = TypeLiteral.get(type);
bind(typeLiteral).to(getServerType());

There are probably some casts missing from that snippet, you may have to 
use raw types to get it to compile, but that's the gist.

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/bdb063fa-a343-46e0-a3f5-27ed92eea610%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to