2009/12/13 dg <[email protected]>

>
> bind( new TypeLiteral<Set<String>>(){} ).to( MyCustomStringSet.class )
>

also from the Guice wiki:

  "Guice has complete type information for everything it injects. If you're
injecting parameterized types, you can inject a TypeLiteral<T> to
reflectively tell you the element type."

so you could even do this:

  bind( new TypeLiteral<Set<String>>(){} ).toProvider(
MyCustomSetProvider.class );

and have TypeLiteral injected in the provider constructor, which would tell
you what sort of set to provide...

Then you can
>
> @Inject SomeClass( Set<String> strings ) { ..... }
> @Inject SomeClass( Provider<Set<String>> stringProvider ) { ..... }
>
> of course, toInstance, toProvider, work too, it's the TypeLiteral
> that's the magic.
>
> -d
>
>
> On Dec 12, 3:50 pm, Grary <[email protected]> wrote:
> > Folks,
> >
> > I want to provide multiple instances of
> > java.util.Set<java.lang.String> in my class, but I just can't seem to
> > get it to work with Guice's Provider<T>.
> >
> > There seems to be a hole in the documentation as far the following key
> > steps are concerned:
> >
> > 1) Can Provider<T> be implemented where T is a generic class?
> > 2) If so, how does the binding look?
> >
> > Any thoughts?
> >
> > Thanks,
> >
> > Grar
>

-- 
Cheers, Stuart

--

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