有匕首时注入依赖时回落到反思的文件? [英] Is there documentation on when Dagger falls back to reflection when injecting dependencies?

查看:125
本文介绍了有匕首时注入依赖时回落到反思的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的团队已经Android应用内通过的匕首依赖注入,我必须说,我们喜欢它这么远。但是,我们要确保我们能有效地使用。我想知道如果任何人都可以解释或者如果有任何文件说明将匕首回落到反射的注入依赖的情况下?

My team has adopted Dagger for dependency injection within our Android app and I must say that we love it so far. However, we want to make sure that we are using it efficiently. I was wondering if anyone can explain or if there is any documentation explaining the cases in which Dagger falls back to reflection for injecting dependencies?

推荐答案

匕首的回退逻辑嵌入其FailoverLoader类。它用于故障切换时,它不能加载ModuleAdapter给定模块,但最新的版本将会失败,错误,如果它不能加载ModuleAdapter。

Dagger's fall-back logic is embedded in its FailoverLoader class. It used to failover when it could not load a ModuleAdapter for a given module, but most recent releases will fail with an error if it cannot load a ModuleAdapter.

目前,匕首将故障转移,如果它不能找到需要注入的给定类型的InjectAdapter类。最常见的情况是,当你有一个可注射型,即没有@Inject领域的抽象父。在这种情况下,没有InjectAdapter将已经为它创建的,并在装入混凝土注射型,所以当,它试图寻找一个适配器对父,不能找到一个,并创建一个反射替身。

Currently, Dagger will fail-over if it cannot find an InjectAdapter class for a given type that needs injecting. The most common case is when you have an abstract parent of an injectable type, that has no @Inject fields. In this case, no InjectAdapter will have been created for it, and so when the concrete injectable type is loaded, it tries to lookup an adapter for the parent, cannot find one, and a reflective stand-in is created.

同样,如果一个人不运行针对装饰用@Inject字段或构造函数的类code代,匕首将下降的回反射那些为好。这其实是相同的逻辑,与上面的继承情况下,它只是继承是不从故障运行code代干的唯一情况。

Similarly, if one does not run code-generation against classes that are decorated with @Inject fields or constructors, Dagger will fall-back to reflection for those as well. It's really the same logic as with the inheritance case above, it's just that inheritance is the only case that doesn't stem from a failure to run the code-generation.

顺便说一句,在谷歌叉在 http://github.com/google/dagger 目前生成处理的适配器父类型头也不抬父适配器(硬codeD母适配器),所以这种故障转移不会在谷歌叉发生。我们还没有公布谷歌叉Maven的时候,因为它已经几乎相同,直到最近,但如果在父类故障转移逻辑是一个问题,你可以提出一个问题,并要求释放。

As an aside, the Google fork at http://github.com/google/dagger currently generates adapters that handle their parent types without looking up an adapter for the parent (hard coded parent adapters), so this fail-over does not occur in the google fork. We haven't released the google fork to maven, as it's been nearly identical up until recently, but if failover logic in parent classes is an issue, you may wish to file an issue and ask for a release.

这篇关于有匕首时注入依赖时回落到反思的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆