Last active
February 15, 2018 16:25
-
-
Save jmfayard/3c60d5491029b8ff1f8f94503db57825 to your computer and use it in GitHub Desktop.
How To Not Use Dagger2
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
fun app() = AppComponent.instance | |
interface AppComponent { | |
val context: Context | |
val retrofit: Retrofit | |
val okHttpClient: OkHttpClient | |
val catRepository: CatRepository | |
val catService: CatService | |
val mainThreadScheduler: Scheduler | |
val backgroundThreadScheduler: Scheduler | |
companion object { | |
lateinit var instance: AppComponent | |
} | |
} |
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
fun app() = AppComponent.instance | |
@Component(modules = [CatModule::class]) | |
interface AppComponent { | |
// ... properties | |
companion object { | |
lateinit var instance: AppComponent | |
} | |
} | |
class CustomApplication : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
AppComponent.instance = DaggerAppComponent.builder()...build() | |
} | |
} |
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
@Component(modules = [CatModule::class]) | |
interface DaggerComponent { | |
fun context(): Context | |
fun retrofit(): Retrofit | |
fun okHttpClient(): OkHttpClient | |
fun catRepository(): CatRepository | |
fun catService(): CatService | |
@Named("MAIN") fun mainThreadScheduler(): Scheduler | |
@Named("BACKGROUND") fun backgroundThreadScheduler(): Scheduler | |
} |
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
@Component(modules = [CatModule::class]) | |
interface AppComponent { | |
val context: Context | |
val retrofit: Retrofit | |
val okHttpClient: OkHttpClient | |
val catRepository: CatRepository | |
val catService: CatService | |
@Named("MAIN") val mainThreadScheduler: Scheduler | |
@Named("Background")val backgroundThreadScheduler: Scheduler | |
} |
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
// Common Module | |
fun common() = AppComponent.instance | |
interface CommonComponent { | |
val retrofit: Retrofit | |
companion object { | |
lateinit var instance: CommonComponent | |
} | |
} | |
interface AppComponent { | |
val context: Context | |
val retrofit: Retrofit | |
companion object { | |
lateinit var instance: AppComponent | |
} | |
} | |
// App Module | |
fun app() = AppComponent.instance | |
interface AppComponent { | |
val context: Context | |
val retrofit: Retrofit | |
companion object { | |
lateinit var instance: AppComponent | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment