Skip to content

Instantly share code, notes, and snippets.

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