romainbsl
03/30/2021, 2:26 PMbind() from...
has been deprecated in benefit of:
bind { singleton { Person("Romain") } }
What's intersting here is that this new bind
function is also compatible with type binding like:
bind<IPerson> { singleton { Person("Romain") } }
this is equivalent to write:
bind<IPerson>() with singleton { Person("Romain") }
Note the you can also use scopes and contextes with this notation, like:
bind<IPerson> { scoped(SessionScope).singleton { Person("Romain") } }
So, expect us to deprecate type binding (bind<TYPE>() with ...
) in a next major release.
2. Simplified API
With this new function comes new possibilities like simple bindings:
- bindSingleton { Person("Romain") }
tags are still available here:
- bindSingleton(tag = "me") { Person("Romain") }
- also available: bindProvider
/ bindFactory
/ bindInstance
/ bindConstant
Those function are not compatible with scopes and contextes
Documentation has been updated in consequences:
https://docs.kodein.org/kodein-di/7.5/core/bindings.html
- Compose support
We are existed to bring to you dependency injection for Compose.
You can use it right now whatever the Compose version you are currently using.
- `Jetpack`| JetBrains
- alpha
| beta01
| beta02
...
Here is an example with Jetpack Compose:
class MainActivity : ComponentActivity(), DIAware {
override val di: DI = DI.lazy {
constant("me") with "Romain"
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
PlaygroundComposeTheme {
withDI {
Greeting()
}
}
}
}
}
@Composable
fun Greeting() {
val me: String by instance("me")
Text(text = "Hello $me!")
}
Full documentation is here:
https://docs.kodein.org/kodein-di/7.5/framework/compose.htmlJoost Klitsie
03/31/2021, 11:04 AMromainbsl
04/01/2021, 7:18 AMJoost Klitsie
04/01/2021, 7:24 AMJoost Klitsie
04/01/2021, 7:25 AMJoost Klitsie
04/01/2021, 7:26 AMromainbsl
04/01/2021, 7:27 AM