Dagger Superiority

When you use the @ Inject-annotated constructor to tell the Dagger how to provide dependency, can you redefine it later in the module? Case: my production code uses a component with an annotated constructor, and I want to override it with a test implementation during testing. Will my override = true Module successfully cancel production implementation during testing?

Or more general questions, which takes precedence, Modules or annotated classes?

+4
source share
1 answer

@ Provides methods always trump @Inject Constructors and no-args constructors (with field injection.

, @Provides , , @Singleton, @Provides, , @Provides .

, "" ... @Module ( = ) ( ). , ( ) :

  • @Module (overrides = true) @
  • @Module (overrides = false) ( ) @
  • @Inject- Just In Time
  • no-arg Just In Time, IF- @Inject.
+5