In dagger 2, Is it possible to do field injection

2019-07-30 03:07发布

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条回答
做自己的国王
2楼-- · 2019-07-30 03:50

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.

查看更多
登录 后发表回答