getAllBindings would be incorrect because that returns Bindings, not
Elements (and TypeListeningBinding is an Element, not a Binding, despite
its name).  But you're right that we should expose all the Elements from
the Injector).

 sam

On Thu, Mar 29, 2012 at 2:36 PM, Alex <[email protected]> wrote:

> FYI, I am ashamed to admit but as a terrible workaround I simply use
> reflection to get at the TypeListenerBindings. It would be nice though if
> these were included from the call to getAllBindings.
>
> Injector injector = Guice.createInjector(...);
>
> Class injectorImplClass =
> Class.forName("com.google.inject.internal.InjectorImpl");
> Field field = injectorImplClass.getDeclaredField("state");
> field.setAccessible(true);
>
> Object state = field.get(injector);
>
> Class stateClass = Class.forName("com.google.inject.internal.State");
> Method method = stateClass.getDeclaredMethod("getTypeListenerBindings");
> method.setAccessible(true);
>
> for (final TypeListenerBinding typeListenerBinding :
> (List<TypeListenerBinding>) method.invoke(state)) {
>     // Do something with the TypeListenerBinding
> }
>
> On Monday, March 26, 2012 9:41:25 PM UTC-5, Alex wrote:
>>
>> I hope I haven't missed anything obvious but is there a way to get the
>> bound TypeListeners for an Injector?  I have poked around with
>> Injector.getAllBindings() which in turn provides access to the
>> Providers but I don't ever see my bound listeners.  The only reason I
>> want to access this information is to be able to easily glean
>> information about my Guice configuration and what exactly is bound
>> through the Injector. I am ultimately hoping to expose this through a
>> simple web interface for environment testing and debugging.
>>
>> I even looked at the Grapher but that didn't seem to provide what I
>> wanted either, assuming once again that I didn't miss something.
>>
>> Thanks!
>
>  --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-guice/-/9tSPMiAyFhAJ.
>
> 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.
>

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