Is it possible to limit type hierarchy scanning with Guice?

 ̄綄美尐妖づ 提交于 2019-12-08 08:03:32

问题


Is there any way, when using Google's Guice injector to limit inheritance depth when scanning a class to find its dependencies ?

I mean, if you define a class A like

class A extends X {
 @Inject
 private B a;
}

And I got class inheritance : A --> X --> Y --> Z

I just want A to be scanned, and X, but not upper classes like Y and Z. I am pretty certain no fields can be injected in neither classes.

My goal is to boost startup phase.

Is that possible ?


回答1:


I don't think it's possible and I'd bet the gain would be negligible. Guice only need to scan the class hierarchy once in order to collect the injection points and the usually more time-consuming part is the injection itself.

The cost of the injection itself is independent of the class hierarchy, it rather depends on the number of objects to be processed and number of fields to be injected.




回答2:


The RoboGuice team is actively working in this area. For those who are interested, RG 3.0 will include a fork of guice based on this technique.

More details here : https://speakerdeck.com/stephanenicolas/blender-boosting-guice-with-annotation-processing



来源:https://stackoverflow.com/questions/21217883/is-it-possible-to-limit-type-hierarchy-scanning-with-guice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!