https://kotlinlang.org logo
#kodein
Title
f

Fabio Santo

05/05/2021, 12:00 AM
Hello mates 👋 Can I please have an updated answer about Kodein DI within the iOS module of a Kotlin Multiplatform Project? I read from slack messages, I need to build a bridge Utility class. Does this still apply? Thanks
r

romainbsl

05/05/2021, 11:36 AM
I’m not sure to understand your question ? Do you mean binding from iOS source set ? Accessing binding from Swift ?
f

Fabio Santo

05/05/2021, 9:50 PM
I'm sorry, I meant injecting, creating modules etc from the iOS side of a Kotlin Multiplatform.
r

romainbsl

05/06/2021, 12:34 PM
So binding Swift types ?
f

Fabio Santo

05/10/2021, 1:19 AM
Copy code
object CommonInjector {
    @ApolloExperimental
    val kodein = DI.lazy {
        import(sharedKodein)
    }

    @ExperimentalCoroutinesApi
    fun searchStore() = kodein.direct.instance<SearchStore>()

}
this ^, is this the right way to inject instances from Swift ?
then in swift ...
Copy code
init() {
        store = CommonInjector().searchStore()
r

romainbsl

05/10/2021, 5:05 AM
Yes it is the simplest way to retrieve dependencies from Swift right now.
However, it is possible to inject instances from Swift by defining few utils from both side (Kotlin and Swift)
👍 1
I might be able to share a Gist to show you how in the next days
👌 1
👀 1
2 Views