Reputation: 61
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?
Upvotes: 4
Views: 2881
Reputation: 95764
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).
Upvotes: 3