-> Here the detailed explanation - *API refact...
# kodein
r
-> Here the detailed explanation - API refactoring 1. Direct binding
bind() from...
has been deprecated in benefit of:
Copy code
bind { singleton { Person("Romain") } }
What's intersting here is that this new
bind
function is also compatible with type binding like:
Copy code
bind<IPerson> { singleton { Person("Romain") } }
this is equivalent to write:
Copy code
bind<IPerson>() with singleton { Person("Romain") }
Note the you can also use scopes and contextes with this notation, like:
Copy code
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:
Copy code
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.html
j
This looks very interesting! I am already using kodein in my compose application, perhaps you can write a blog post about this and post it to the #compose channel? I think those people are eager to have a compose ready DI framework.
r
It's planned to make a video about it, but times fly, so don't know when we'll have the time to do this.
j
I think if you are fast you might just win a good audience
As now it is totally lacking
People are waiting for dagger or hilt support, perhaps if they can already use this they will stick with it :)
r
Yes, I should put this on my TODO with high priority, thanks for the advice :)