问题
Is it possible to do field injection and constructor injection for the same class ?
For instance : implementation is like
activity
- field injection of fragment.
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