https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
k

Kweku

04/04/2020, 3:25 PM
How is everyone currently handling dependency Injection? The app I'm working on for Android and IOS use KMP for the domain and data layers then Flutter for the UI. I was thinking of handling DI outside of KMP, for exame using dagger for Android as in native Android I've mages to use Dagger in a way where my domain and data layers have no dependencies on Dagger. The problem is I'm unsure about doing this for Ios having never developed for it before although I've read Needle and Dagger are similar? I've seen Koin( which I've used before) and KodeIn (which I haven't) be mentioned but haven't seen any example usage and theres also the option of doing it myself(Pure DI) Basically I've done a some research but it's the native part that is making me wary as I've seen things about concurrency issues TDLR: I'd like to know if anyone has any experience with DI on KMP
j

judrummer

04/04/2020, 3:47 PM
I use Kodein
r

russhwolf

04/04/2020, 4:06 PM
We’re using Koin in KaMPKit if you want to see some sample usage. Note that this is actually an internal fork to better handle native threading, which will be upstreamed in a future Koin release. Common: https://github.com/touchlab/KaMPKit/blob/master/shared/src/commonMain/kotlin/co/touchlab/kampstarter/Koin.kt Platforms: https://github.com/touchlab/KaMPKit/blob/master/shared/src/iosMain/kotlin/co/touchlab/kampstarter/KoiniOS.kt and https://github.com/touchlab/KaMPKit/blob/master/shared/src/androidMain/kotlin/co/touchlab/kampstarter/KoinAndroid.kt
k

Kweku

04/04/2020, 4:24 PM
@russhwolf thank you, you mean the one by @kpgalligan ? I'm guessing you cal initKoin in the Application/ MainActivity or AppDelegate but what is the appDeclaration parameter and the type (KoinAppDeclaration ={}) ?
r

russhwolf

04/04/2020, 4:26 PM
b

Brendan Weinstein

04/04/2020, 5:14 PM
I am doing manual for the short-to-medium-run future
k

Kweku

04/04/2020, 5:27 PM
@russhwolf ahh that makes sense, what issues are there witch concurrency etc
@Brendan Weinstein how are you finding that?
s

saket

04/04/2020, 6:41 PM
I've a similar setup like @russhwolf: Koin in common code, Dagger in Android. You can take a look here: https://github.com/saket/press
k

Kweku

04/04/2020, 8:22 PM
@saket why both Koin and Dagger rather than just Dagger in Android?
s

saket

04/04/2020, 8:25 PM
Not sure if i understood your question. Koin is only used in common code written with kotlin multiplatform.
b

Brendan Weinstein

04/04/2020, 10:30 PM
@Kweku I am using multiplatform on a smaller-to-midsize project, so it's not that bad.
c

coletz

04/06/2020, 9:51 PM
I am using koin for a mpp project, basically copied kamp kit code. For a mpp + flutter project like yours, no DI at all. Honestly having two totally separated code bases (different lang) I wasn't sure DI was worth for such a small project
7 Views