You canot intercept methods on instances created by a provider. What guice does 
is to create a subclass of the thing you want to to intercept. But when you use 
a provider to create this object you are calling new yourself which makes it 
impossible for guice to sneak in the subclass.

Therefore interception of methods only works on instances created by guice 
(there is no 'new' in your code)

Am 23. April 2016 19:44:05 MESZ, schrieb Pablo perez <politr...@gmail.com>:
>
>
>I´m using Guice TypeListener to intercept a map instance generated by a
>
>provider.
>
>Here the config method where I bind my listener
>
>@Overridepublic void addConfig() {
>    MapListener mapListener = new MapListener();
>    requestInjection(mapListener);
>    bindListener(Matchers.any(), mapListener);}
>
>This is the map instance created by this provider
>
>  @Provides
>  Map<String, String> mapTest(){
>    return new HashMap<>();
>  }
>
>This is the listener class to detect the map instance
>
>public class MapListener implements TypeListener {
>
>    @Override
>public <I> void hear(final TypeLiteral<I> typeLiteral, TypeEncounter<I>
>typeEncounter) {
>        typeEncounter.register((InjectionListener<I>) i -> {
>        if(i.getClass().isAssignableFrom(Map.class)){
>              System.out.println("DI:"+ i.getClass()
>                                .getName());
>             //TODO:Logic to modify map
>        }
>        });
>    }}
>
>The problem is the Map is never passed to the hear method. Am I doing 
>something wrong?
>
>Regards.
>
>-- 
>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 google-guice+unsubscr...@googlegroups.com.
>To post to this group, send email to google-guice@googlegroups.com.
>Visit this group at https://groups.google.com/group/google-guice.
>To view this discussion on the web visit
>https://groups.google.com/d/msgid/google-guice/dd19c60f-b7a0-4e25-8fb0-eac9d9fcbc80%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/7253D50F-0805-4FA7-9CA8-278A199C2B13%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.

Reply via email to