Just spewing out ideas in my head - warning: they may be stupid, or
impossible in Java since I'm in ActionScript mode and I've been working on
my AS injector. So forgive lapses in existing Guice / Java syntax ;-)

What if there were some sort of hierarchical scope maintained while
injecting a particular object graph that could be hooked into at bind time?
Something along the lines of:

class Person {
  @Inject
  @Inherit(annotation=Named.class)
  @Named("direct")
  Phone directPhone;

  @Inject
  @Named("floor")
  @Inherit(annotation=Named.class)
  Phone floorPhone;
}

@Named("accounts")
class Accounts {
  @Inject
  @Named("bob")
  Person bob;

  @Inject
  @Named("sue")
  Person sue;
}

bind(Phone.class).annotatedWith(Names.named("direct")).inheritingAnnotation(Names.named("bob")).to(bobsDeskPhone);
bind(Phone.class).annotatedWith(Names.named("direct")).inheritingAnnotation(Names.named("sue")).to(suesDeskPhone);
bind(Phone.class).annotatedWith(Names.named("floor")).inheritingAnnotation(Names.named("accounts")).to(accountsReceptionPhone);

Thoughts?

-Josh

On Wed, Sep 10, 2008 at 2:27 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]>wrote:

>
>
>
> On Sep 9, 10:06 am, Mikkel Petersen <[EMAIL PROTECTED]> wrote:
> > Thanks I'll take a look at it. Wish there was a more simple way to do
> > it though.
>
> Definitely, we have this problem internally at Google as well.
> We're planning on building out the hierarchical injectors so
> they solve this problem natively.
>
> If you're curious, I've written a blog post that attempts to
> explain the motivations for hierarchical injectors:
> http://publicobject.com/2008/06/whats-hierarchical-injector.html
>
> >
>


-- 
"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
-~----------~----~----~----~------~----~------~--~---

Reply via email to