Last active
March 12, 2020 16:25
-
-
Save thegarlynch/e9002b89613d2c1bb017f296a05ea832 to your computer and use it in GitHub Desktop.
tutorial-dagger-snippet-add-component
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
import dagger.Component | |
import javax.inject.Inject | |
import javax.inject.Singleton | |
@Component | |
@Singleton | |
interface TutorialComponent { | |
val contohMelaluiComponent : Contoh | |
fun inject(mainActivity : MainActivity) | |
@Component.Factory | |
interface Factory { | |
fun create() : TutorialComponent | |
} | |
} | |
// Class contoh yang akan kita suntik / inject (harus punya anotasi @Inject ya.) | |
class Contoh @Inject constructor(private val anakContoh: AnakContoh){ | |
val nomor by lazy { (1..10).random() } | |
val nomorAnak get() = anakContoh.nomor | |
} | |
class AnakContoh @Inject constructor(){ | |
val nomor by lazy { (1..10).random() } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment