X-Blaster
X-Blaster

Reputation: 1771

Intercept a constructor with google guice

I want to intercept a constructor with Google guice.

I have added my annotation mark on TYPE but I have some problem with the "bindInterceptor"

If I write

bindInterceptor(Matchers.annotatedWith(ReactToLoad.class),
                Matchers.any(),
                new ReactToLoadInterceptor());

This will run the interceptor on each method. (it's bad and it's normal)

bindInterceptor(                Matchers.any(),
                                Matchers.annotatedWith(ReactToLoad.class),
                new ReactToLoadInterceptor());

If I run the code just below, I MUST put the annotation on the constructor method (it works) but I prefer to put this annotation on top of classes.

I just need a method Matchers for the constuctor method but I don't find it with some googling.

Can you help me ?

Upvotes: 2

Views: 1098

Answers (1)

ColinD
ColinD

Reputation: 110046

No, it isn't possible to intercept constructor calls... only method calls. I don't know why you want to do this, but you may want to look in to Guice's SPI, specifically InjectionListener.

Upvotes: 4

Related Questions