Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Annotation interceptor using Dagger 2

Is there a way you could use Dagger 2 to inject a custom annotation. Example:

@CustomAnnotation 
method(){}

I want this annotation to invoke an intercepting class. I know that Guice allows you to bind custom annotation but what about Dagger 2?

like image 874
Taha Avatar asked Oct 15 '25 09:10

Taha


1 Answers

Though Dagger does not support AOP interception or custom injections the same way that Guice does, Dagger does have an SPI introduced in Dagger 2.15 that allows you to specify binding graph plugins for validation and code generation. You might use this to generate code that accomplishes what you want based on the BindingGraph that Dagger produces. See BindingGraphPlugin for more details.

You might also choose instead to develop independent code generators that you can refer to from Dagger or any other framework, as Google has done with the Auto package (AutoValue, AutoFactory, AutoService, and so forth).

like image 189
Jeff Bowman Avatar answered Oct 16 '25 22:10

Jeff Bowman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!