java - what's the difference between these two binding declarations with Google Guice? -


what's difference between

bind(fooimpl.class).in(scopes.singleton); bind(foo.class).to(fooimpl.class); 

and

bind(foo.class).to(fooimpl.class).in(scopes.singleton); 

with google guice?

edit:

the second declaration create 2 instances on singleton in project working on. reference here

in reference google guice documentation:

in linked bindings, scopes apply binding source, not binding target. suppose have class applebees implements both bar , grill interfaces. these bindings allow 2 instances of type, 1 bars , grills:

bind(bar.class).to(applebees.class).in(singleton.class); bind(grill.class).to(applebees.class).in(singleton.class); 

this because scopes apply bound type (bar, grill), not type satisfies binding (applebees). allow single instance created, use @singleton annotation on declaration class. or add binding:

bind(applebees.class).in(singleton.class); 

so, it's possible have 2 instances of fooimpl in second way not first way of writing binding.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -