You're right, somehow I forgot to remove the Named annotation from the
class. It is working now. Thanks.
Yunfeng Hou
On Jul 11, 2:48 am, Peter Schmitt <
ara...@gmail.com> wrote:
> Hi Yunfeng,
>
> protected void configure() {
>
> > bind(HistoryManager.class).annotatedWith(Names.named("hm1")).to
> > (HistoryManager.class);
> > bind(HistoryManager.class).annotatedWith(Names.named("hm2")).to
> > (HistoryManager.class);
> > }
>
> These bindings configure nothing about the number of times that the
> constructor of your HistoryManager class is called. All that you say here is
> that you want *any *instance of HistoryManager injected when it is annotated
> with @Named("hm1") or @Named("hm2"), versus maybe injecting a subclass of
> HistoryManager if it is not annotated (a binding for that is missin though,
> so I'd say the two bindings are superfluous).
>
> The reason why your history manager constructor might only be called once is
> that you might have @Singleton annotation on the class or you bind it in
> singleton scope elsewhere (i.e. you're calling
> bind(HistoryManager.class).in(Singleton.class)).
>
> If you would like to have two distinct HistoryManager instances injected
> into your HistoryManagers constructor, remove the singleton scoping and
> either
>
> - Use the constructor you are now using, maybe without annotations or
> - Inject a provider (Provider<HistoryManager> managerProvider) and get