Skip to content

Instantly share code, notes, and snippets.

@alejandro-rios
Last active September 13, 2019 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alejandro-rios/9ef3e63bdf4f35db888c2b8aa50f91d0 to your computer and use it in GitHub Desktop.
Save alejandro-rios/9ef3e63bdf4f35db888c2b8aa50f91d0 to your computer and use it in GitHub Desktop.
Basic Hello World with Koin
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