https://kotlinlang.org logo
#android
Title
# android
m

Matt Rea

10/25/2018, 8:52 PM
what is your
single
declaration in your module? If you’re doing
single<ComponentA>()
, I would change it to
single { ComponentA(get(), get()) }
. Omitting parameters and having koin find them is experimental. As far as I can tell from the source code its based on reflection https://github.com/InsertKoinIO/koin/blob/e159f2dd845990a9b5588d142692d132d7597708/koin-projects/koin-core/src/main/kotlin/org/koin/core/instance/InstanceHolder.kt Here’s a Retrofit example in my app
Copy code
val networkModule: Module = module {
    single { createWebApi<AuthApi>(get<NetworkClient>().defaultRetrofit) }
    single { createWebApi<MapBoxApi>(get<NetworkClient>().mapBoxRetrofit) }
}
inline fun <reified T> createWebApi(retrofit: Retrofit): T = retrofit.create(T::class.java)
👍 1
g

GurpreetSK

10/26/2018, 6:22 AM
Thanks a lot! This helped. Can you point to some resource where I can read more about this?
5 Views