Hi All,
I found a very interesting thing about the scope of the provider. Here is
the code of BaseModelProvider
public class BaseModelProvider implements Provider<Model> {
private int num;
@Override
public Model get() {
System.out.println(num++);
return new Model();
}
--------------------------------------------------------------------
this.bind(Model.class).annotatedWith(Names.named("index")).toProvider(new
BaseModelProvider());
This way gives : 1,2,3,4,5,6.....(in singleton scope)
---------------
this.bind(Model.class).annotatedWith(Names.named("index")).toProvider(BaseModelProvider.class);
This way gives : 0,0,0,0,0.....(in request scope)
I don't understand the different about this two definitions. So anybody
knows how it works ? many thanks!
BTW: I just want bind many providers dynamically within a loop, So I am
using the .toProvider(Prvider<? extends Model> instance).
--
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/-/ZsZa_iHVMdAJ.
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.