https://kotlinlang.org logo
#kotlin-inject
Title
# kotlin-inject
k

Kyle

09/29/2023, 7:19 PM
are there any examples of using kotlin-inject with sqldelight in a kmp project that also has an ios app? I’m not understanding the best way to use kotlin-inject in this scenario based on the readme examples
e

evant

09/29/2023, 7:34 PM
It doesn't have sqldelight but there's a kmp sample here https://github.com/evant/kotlin-inject-samples/tree/main/multiplatform/greeter
k

Kyle

09/30/2023, 2:15 PM
So here’s one thing I’m running into. I’ve created an ApplicationComponent similar to that sample. https://github.com/EMAssistant/EMAssistant-mobile/blob/main/shared/src/iosMain/kotlin/net/emassistant/emassistant/ApplicationComponent.kt. I also created another class that uses the same ApiClient as in ApplicationComponent and tried using @Inject for it. https://github.com/EMAssistant/EMAssistant-mobile/blob/main/shared/src/commonMain/[…]ssistant/emassistant/common/models/viewmodel/WhoamiViewModel.kt I tried injecting the ApplicationComponent into the ios app https://github.com/EMAssistant/EMAssistant-mobile/blob/main/iosApp/iosApp/FRAssistantApp.swift#L6 and then separately calling the viewmodel, https://github.com/EMAssistant/EMAssistant-mobile/blob/main/iosApp/iosApp/MainView.swift#L10. I have a debug line and I’m noticing that init is getting called twice in that ApiClient, https://github.com/EMAssistant/EMAssistant-mobile/blob/main/shared/src/commonMain/[…]/emassistant/emassistant/common/network/EMAssistantApiClient.kt How should I be setting this up to properly inject classes where they’re needed? (Also I know my code base looks messy, I’m learning mobile dev and I’m refactoring as I learn what I need to do. Any suggestions are appreciated)
10 Views