Blundell
01/24/2020, 2:29 PMprivate val network1: Module
get() = module {
factory<RefreshAuthTokenInterceptor>() bind Interceptor::class
}
In Android Module 2)
private val network2: Module
get() = module {
factory<HeadersInterceptor>() bind Interceptor::class
factory<RetryInterceptor>() bind Interceptor::class
single<InterceptorFactory> {getAll<Interceptor>()}
}
App init:
startKoin {modules(listOf(network1, network2))}
In terms of gradle: App module depends on Module 1 which depends on Module 2
But the getAll<Interceptor>()
is only returning the 2 instances in the same Koin module. Is this expected behaviour? Is there anyway to get all 3 of the Interceptors?diesieben07
01/24/2020, 2:46 PMdiesieben07
01/24/2020, 2:47 PMinterface Interceptor
class InterceptorFactory(val interceptors: List<Interceptor>)
class RefreshAuthTokenInterceptor : Interceptor
class HeadersInterceptor : Interceptor
class RetryInterceptor : Interceptor
private val network1: Module
get() = module {
factory<RefreshAuthTokenInterceptor>() bind Interceptor::class
}
private val network2: Module
get() = module {
factory<HeadersInterceptor>() bind Interceptor::class
factory<RetryInterceptor>() bind Interceptor::class
single<InterceptorFactory> {
InterceptorFactory(getAll<Interceptor>())
}
}
fun main() {
val app = startKoin { modules(listOf(network1, network2)) }
println(app.koin.get<InterceptorFactory>().interceptors.map { it::class.simpleName })
}
Prints: [HeadersInterceptor, RetryInterceptor, RefreshAuthTokenInterceptor]
Blundell
01/24/2020, 3:03 PM