In dagger 2, Is it possible to do field injection and constructor injection for the same class?

徘徊边缘 提交于 2019-12-11 10:31:51

问题


Is it possible to do field injection and constructor injection for the same class ?

For instance : implementation is like

  1. activity

    • field injection of fragment.
  2. fragment (activityscoped)

    • non parameter constructor injection (downstream )
    • field injection of presenter(Fragmentscoped) class.

回答1:


Yes, you can inject constructors, methods, and fields within the same class. Dagger will automatically inject fields and call @Inject-annotated methods as part of the construction process.



来源:https://stackoverflow.com/questions/47444206/in-dagger-2-is-it-possible-to-do-field-injection-and-constructor-injection-for

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