Last active
March 12, 2020 16:32
-
-
Save thegarlynch/0e3c1311ea85c19969a1ef3e79fdc5a7 to your computer and use it in GitHub Desktop.
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 android.os.Bundle | |
import android.util.Log | |
import androidx.appcompat.app.AppCompatActivity | |
import javax.inject.Inject | |
class MainActivity : AppCompatActivity() { | |
@Inject lateinit var contoh: Contoh | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
// DaggerTutorialComponent akan otomatis di create setelah build | |
val component = DaggerTutorialComponent.create() | |
component.inject(this) | |
Log.d("Tutorial", "Contoh 1 : ${contoh.nomor} ${contoh.nomorAnak}") | |
// Kalian juga bisa mengambil instansi contoh diatas dengan | |
val contoh2 = component.contohMelaluiComponent | |
Log.d("Tutorial", "Contoh 2 : ${contoh2.nomor} ${contoh2.nomorAnak}") | |
// Tapi kenapa harus make dagger ? harusnya kan bisa dibuat kayak gini : | |
val contoh3 = Contoh(AnakContoh()) | |
Log.d("Tutorial", "Contoh Tanpa Dagger : ${contoh3.nomor} ${contoh3.nomorAnak}") | |
// Gak susah toh. | |
// Perhatikan bahwa kita tidak perlu menginisialisasi AnakContoh | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment