Yes, you will have 2 task-scoped EM bindings in the second case. And 1 in the first (all 3 bindings pointing to the impl).
Dhanji. On Mon, Sep 15, 2008 at 10:53 AM, Josh McDonald <[EMAIL PROTECTED]> wrote: > Correct me if i'm wrong, but when you do this: > > bind(EntityManagerImpl.class).in(TaskScoped.class); > bind(EntityLoader.class).to(EntityManagerImpl.class); > bind(ReferenceFactory.class).to(EntityManagerImpl.class); > > You're asking guice to do 3 things: > > > 1. Bind EntityManagerImpl in TaskScoped > 2. Bind EntityLoader tp EntityManagerImpl > 3. Bind ReferenceFactory to EntityManagerImpl > > When you do this: > > bind(EntityLoader.class).to(EntityManagerImpl.class).in(TaskScoped.class); > > bind(ReferenceFactory.class).to(EntityManagerImpl.class).in(TaskScoped.class); > > You're asking for two things: > > 1. Bind EntityLoader in TaskScoped, implemented by EntityManagerImpl > 2. Bind ReferenceFactory in TaskScoped, coincidently also implemented > by EntityManagerImpl > > In the second part, there's nothing telling Guice that EntityManagerImpl is > in TaskScope, only that EntityLoader and ReferenceFactory are. So the system > knows that for each Task you've got one EntityLoader and one > ReferenceFactory, it doesn't have a clue (or care) how mamy > EntityManagerImpls are required to achieve that. Everything following > bind(foo) applies to the binding for Foo, it doesn't "leak out" into > EntityManagerImpl If you want to bind EntityManagerImpl to another impl or > to a scope, you have to do it either with the annotations or a binding of > its own. > > -Josh > > On Mon, Sep 15, 2008 at 10:35 AM, Esko Luontola <[EMAIL PROTECTED]>wrote: > >> >> I looked at the source, and actually all the to(...) methods delegate >> to the to(Key) method. Also the javadocs of to() say that it "binds to >> another binding". >> >> > > > -- > "Therefore, send not to know For whom the bell tolls. It tolls for thee." > > http://flex.joshmcdonald.info/ > > :: Josh 'G-Funk' McDonald > :: 0437 221 380 :: [EMAIL PROTECTED] > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "google-guice" group. 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 -~----------~----~----~----~------~----~------~--~---
