Hi Jochen,
to query for the correct result you can just use a Key based on the correct
TypeLiteral for the multi bound instances.
In your example this would be:
Set<LifecycleAware> lifecycleAwares = pInjector.getInstance(Key.get(new
TypeLiteral<Set<LifecycleAware>>(){}));
If your getLifecycleAwares() method really needs to be a List instead of a
Set, you need to wrap/copy the retrieved Set, e.g. through Guavas
ImmutableList.copyOf(lifecycleAwares) or something similar.
Regards,
Johannes
On Wed, Sep 25, 2013 at 1:24 PM, Jochen Wiedmann
<[email protected]>wrote:
>
> Hi,
>
> I have read about the MultiBinder. As such, my application contains code
> like this:
>
> Multibinder<LifecycleAware> mb = Multibinder.newSetBinder(binder,
> LifecycleAware.class);
> mb.addBinding().to(DbInitializer.class);
>
> However, now I'd like to have omthing like this:
>
> public List<LifecycleAware> getLifecycleAwares(Injector pInjector)
> {
> }
>
> In other words, I'd like to query the Injector programmatically for
> implementations of LifecycleAware.
>
> How would I do this?
>
> Thanks,
>
> Jochen
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/google-guice.
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.