The first way you implicitly bind to an instance (so provider is
singleton itself - guice will never instantiate it):
bind(BaseModelProvider.class).toInstance(new BaseModelProvider());
bind(Model.class).annotatedWith(Names.named("index")).toProvider(BaseModelProvider.class);
The second way you implicitly bind in prototype scope (no scope):
bind(BaseModelProvider.class);
bind(Model.class).annotatedWith(Names.named("index")).toProvider(BaseModelProvider.class);
If you want your providers to be in some scope then you should let
Guice create them for you and either annotate them with scoping
annotation (e.g. with @Singleton) or bind them in scope (like
bind(BaseModelProvider.class).in(Singleton.class);).
2013/1/5 Michael <
fuh...@gmail.com>:
> --
> 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
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.