I have two android modules with two koin modules: ...
# koin
b
I have two android modules with two koin modules: In Android Module 1)
Copy code
private val network1: Module
        get() = module {
            factory<RefreshAuthTokenInterceptor>() bind Interceptor::class
        }
In Android Module 2)
Copy code
private val network2: Module
        get() = module {
            factory<HeadersInterceptor>() bind Interceptor::class
            factory<RetryInterceptor>() bind Interceptor::class

            single<InterceptorFactory> {getAll<Interceptor>()}
        }
App init:
Copy code
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?
d
I can't reproduce your problem. With the code you provided I get all 3.
My test:
Copy code
interface 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]
b
hmm thanks, I'll have to understand what the difference is in my actually code base then!