Skip to content

Instantly share code, notes, and snippets.

@desseim
Last active October 7, 2015 15:10
Show Gist options
  • Save desseim/8244457d5a3b1dcdb954 to your computer and use it in GitHub Desktop.
Save desseim/8244457d5a3b1dcdb954 to your computer and use it in GitHub Desktop.
Injection in >= M14 Kotlin code with Dagger2
class ExampleInjectedActivity : Activity() {
@Inject lateinit var controller: ExampleController
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.example_layout)
//controller.doThing() // would compile but throw at runtime
component().inject(this)
controller.doThing() // works, no need for null-safe syntax
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment