Lukasz Kalnik
11/09/2021, 5:07 PMshared
:
CommonModule.kt:
val commonModule = module {
single<HttpClient> { TmdbApi.createHttpClient() }
single<TmdbApi> { TmdbApi(client = get()) }
}
fun initKoin() = startKoin {
modules(CommonModule.module)
}
In the Android app I can inject dependencies very easily:
val tmdbApi: TmdbApi by inject()
In the iOS AppDelegate I call CommonModuleKt.doInitKoin()
How can I inject the dependencies in the iOS ContentView
?Mustafa Ozhan
02/16/2022, 7:52 AM@StateObject var observable: CalculatorObservable = koin.get()
Lukasz Kalnik
02/16/2022, 8:53 AMshared
module inside `iosMain`:
https://github.com/lukaszkalnik/TmdbApp4/blob/master/shared/src/iosMain/kotlin/com/kalnik/tmdbapp4/di/Koin.ktLukasz Kalnik
02/16/2022, 8:55 AMiosApp
module I created a Koin.swift
file where I get the Koin
instance from the shared module:
https://github.com/lukaszkalnik/TmdbApp4/blob/master/iosApp/iosApp/Koin.swiftLukasz Kalnik
02/16/2022, 8:56 AMKoin
instance I can call the extension methods which I defined in shared/iosMain
to get particular dependencies:
https://github.com/lukaszkalnik/TmdbApp4/blob/99572639d32864b0a74baaa98bd31e1680259a63/iosApp/iosApp/TV%20Show%20Summary/TVShowsViewModel.swift#L7Stylianos Gakis
02/16/2022, 9:12 AMLukasz Kalnik
02/16/2022, 9:18 AMMustafa Ozhan
02/16/2022, 6:44 PM@StateObject var observable: CalculatorObservable = koin.get()
another file
@StateObject var observable: SettingsObservable = koin.get()
so by this way I just use koin.get()
everywhere