Android-rocks
Android-rocks

Reputation: 109

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

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.

Upvotes: 1

Views: 343

Answers (1)

Jeff Bowman
Jeff Bowman

Reputation: 95654

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.

Upvotes: 1

Related Questions