This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomePresenterTest { | |
@Test | |
fun doSomeWork() { | |
val profileRepository = Mockito.mock(ProfileRepository::class.java) | |
val someRepository = Mockito.mock(SomeRepository::class.java) | |
val underTest = SomePresenter( | |
profileRepository, | |
someRepository | |
) | |
// Trigger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeActivity : DaggerAppCompatActivity() { | |
@Inject | |
lateinit var somePresenter: SomePresenter | |
override fun onCreate(savedInstanceState: Bundle?) { | |
//... | |
somePresenter.doSomeWork() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TheApplication : Application(), HasAndroidInjector { | |
@Inject | |
lateinit var injector: DispatchingAndroidInjector<Any> | |
override fun onCreate() { | |
super.onCreate() | |
DaggerAppComponent.create().inject(this) | |
} | |
override fun androidInjector(): AndroidInjector<Any> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
class CommonRepositoryModule { | |
@Provides | |
fun providesProfileRepository(): ProfileRepository { | |
return ProfileRepository() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module(includes = [CommonRepositoryModule::class]) | |
abstract class AppModule { | |
/** | |
* Connect SomeActivity's sub-graph to the App's Dependency Graph | |
*/ | |
@ContributesAndroidInjector(modules = [SomeActivityModule::class]) | |
abstract fun contributeSomeActivity() : SomeActivity | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeActivity : DaggerAppCompatActivity { | |
@Inject lateinit var profileRepository: ProfileRepository | |
fun onCreate() { | |
//... | |
presenter = SomePresenter(profileRepository, ...) | |
presenter.doSomeWork() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
class SomeActivityModule { | |
@Provides | |
fun provideSomeRepository(): SomeRepository { | |
return SomeRepository() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module(includes = [CommonRepositoryModule::class]) | |
abstract class AppModule { | |
/** | |
* Connect SomeActivity's sub-graph to the App's Dependency Graph | |
*/ | |
@ContributesAndroidInjector(modules = [SomeActivityModule::class]) // HERE | |
abstract fun contributeSomeActivity() : SomeActivity | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeActivity : DaggerAppCompatActivity() { | |
@Inject | |
lateinit var profileRepository: ProfileRepository | |
@Inject | |
lateinit var someRepository: SomeRepository | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomePresenter @Inject constructor( | |
val profileRepository: ProfileRepository, | |
val someRepository: SomeRepository | |
) { | |
fun doSomeWork() { | |
println("doSomeWork") | |
} | |
} |