Skip to content

Instantly share code, notes, and snippets.

@tfcporciuncula
tfcporciuncula / ApplicationComponent.kt
Created April 7, 2019 13:52
ApplicationComponent.kt
@Component(modules = [ApplicationModule::class, ...])
interface ApplicationComponent {
fun plus(bookModule: BookModule): BookComponent
...
}
private val presenter =
MyApplication
.component
.plus(BookModule(this))
.presenter
@tfcporciuncula
tfcporciuncula / BookInjection.kt
Last active April 7, 2019 14:10
BookInjection.kt
@Subcomponent(modules = [BookModule::class])
interface BookComponent {
// let's assume BookPresenter has an @Inject-annotated constructor
val presenter: BookPresenter
}
@Module
class BookModule(@get:Provides val bookView: BookView)
@tfcporciuncula
tfcporciuncula / BookInjection.kt
Last active April 7, 2019 14:12
BookInjection.kt
@Subcomponent
interface BookComponent {
@Subcomponent.Builder
interface Builder {
@BindsInstance fun bookView(bookView: BookView): Builder
fun build(): BookComponent
}
val presenter: BookPresenter
@tfcporciuncula
tfcporciuncula / BookInjection.kt
Created April 8, 2019 09:16
BookInjection.kt
@Subcomponent
interface BookComponent {
@Subcomponent.Factory
interface Factory {
fun create(@BindsInstance bookView: BookView): BookComponent
}
val presenter: BookPresenter
}
@tfcporciuncula
tfcporciuncula / ApplicationInjection.kt
Created April 8, 2019 18:33
ApplicationInjection.kt
@Component(modules = [ApplicationModule::class, ...])
interface ApplicationComponent {
...
}
@Module
class ApplicationModule(private val applicationContext: Context) {
@Provides fun provideApplicationContext() = applicationContext
}
@tfcporciuncula
tfcporciuncula / ApplicationModule.kt
Created April 8, 2019 18:34
ApplicationModule.kt
@Module
class ApplicationModule(@get:Provides val applicationContext: Context)
@tfcporciuncula
tfcporciuncula / MyApplication.kt
Created April 9, 2019 07:34
Creating component
DaggerApplicationComponent
.builder()
.applicationContext(applicationContext)
.build()
@tfcporciuncula
tfcporciuncula / BookPresenterModule.kt
Created April 15, 2019 17:07
BookPresenterModule.kt
@Module
object BookPresenterModule {
@Provides @JvmStatic
fun provideBookPresenter(bookPresenter: BookPresenterImpl): BookPresenter = bookPresenter
}
@tfcporciuncula
tfcporciuncula / BookPresenterModule.kt
Created April 15, 2019 17:08
BookPresenterModule.kt
@Module
abstract class BookPresenterModule {
@Binds abstract fun bindBookPresenter(bookPresenter: BookPresenterImpl): BookPresenter
}