Last active
September 13, 2019 18:57
-
-
Save alejandro-rios/9ef3e63bdf4f35db888c2b8aa50f91d0 to your computer and use it in GitHub Desktop.
Basic Hello World with Koin
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 Info(val text: String) | |
// Module | |
val bag = module { | |
single { Info("Hello Koin") } | |
} | |
// MainActivity | |
class MainActivity : AppCompatActivity() { | |
// Retrieve Dependencies | |
private val magicBox: Info by inject() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
// Bind with our activity | |
startKoin { | |
// Android context | |
androidContext(this@MainActivity) | |
// modules | |
modules(bag) | |
} | |
text_view.text = magicBox.text | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment