You might want to use a dedicated provider (that will solve part of
your problem)

  class SinkProvider implements Provider<Sink> {
    @Inject DependencyOfSink1 dep1
    @Inject DependencyOfSink2 dep2
    @Inject DependencyOfSink3 dep3
    SinkProvider(String name) { ...
    Sink get() { return new Sink(name, dep1, dep2, dep3); }
  }

PL

On Feb 20, 12:02 pm, dg <[email protected]> wrote:
> Hello -
>
> "@Inject @Named("foo") Sink sink" -- simple enough, just bind
> ( Sink.class ).annotatedWith( Names.named("foo").to(....).  The rub is
> that I need to pass the string "foo" into the factory which actually
> creates 'Sink'.  Also, the factory needs to be guice-created (of
> course!)
>
> I know the list of names right now as they're hard-coded into my
> module (although I'd like to switch this to multibindings at some
> point)
>
> My solution now is terribly hacky -- it amounts to this:
>
> Set<String> sinkNames = .... // would prefer multi bindings
> for( String name : sinkNames )
> bind( Sink.class ).annotatedWith( Names.named( name ) ).toProvider
> ( SinkProvider.class ).in( new TerribleHackScope( name ) );
>
> And in TerribleHackScope I put the name on a thread local before
> unscoped.get(), and SinkProvider reaches into that thread local for
> the name of the sink to create and passes it to the (injected)
> factory.  All this leaves a bad hacker taste.
>
> Any ideas?
> Feeling I'm missing somethign obvious,
> -d
--~--~---------~--~----~------------~-------~--~----~
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