【发布时间】:2018-08-01 02:07:29
【问题描述】:
有没有办法可以使用 dagger 2 注入自定义注释。示例
@CustomAnnotation 方法(){}
我希望这个注解调用一个拦截类。我知道 Guive 允许您绑定自定义注释,但是 Dagger 2 呢?
【问题讨论】:
标签: java dependency-injection annotations guice dagger-2
有没有办法可以使用 dagger 2 注入自定义注释。示例
@CustomAnnotation 方法(){}
我希望这个注解调用一个拦截类。我知道 Guive 允许您绑定自定义注释,但是 Dagger 2 呢?
【问题讨论】:
标签: java dependency-injection annotations guice dagger-2
虽然 Dagger 不像 Guice 那样支持 AOP interception 或 custom injections,但 Dagger 确实有 an SPI introduced in Dagger 2.15 允许您指定绑定图插件以进行验证和代码生成。你可以使用它来生成代码,根据 Dagger 生成的 BindingGraph 来完成你想要的。详情请见BindingGraphPlugin。
您也可以选择开发独立的代码生成器,您可以从 Dagger 或任何其他框架中引用它们,就像 Google 对 Auto package(AutoValue、AutoFactory、AutoService 等)所做的那样。
【讨论】: