Caio Costa
05/24/2024, 7:42 PMval module = lazyModule {
singleOf(::ChuckerInterceptor) bind Interceptor::class
single { newInstance(interceptor = get()) }
}
And this is the dependency needing method:
//SourceConnector.kt
fun Scope.newInstance(
baseUrl: String = BuildConfig.BASE_URL,
interceptor: Interceptor,
): HttpClient =
HttpClient(OkHttp) {
...
...
}
I tried to reference that method in different manners but none worked
First I turned the file into an object and tried to reference it (Had to remove Koin's Scope requirement since AFAIK singleOf does not provide a Scope context):
singleOf(SourceConnector::newInstance)
Then, I reverted that change and went back to having just a file and tried to reference that method:
singleOf(::newInstance)
But I always got an exception that says Koin could not find the definition (NoBeanDefFoundException)
I'd like to keep it as an extension function that does not require a prior object creation to be accessed if possible
Do you think there is a way to use singleOf(::X) in this case or should I keep the code as it is?
Thank you so much in advance 🤝️arnaud.giuliani
05/28/2024, 9:17 AMarnaud.giuliani
05/28/2024, 9:17 AMarnaud.giuliani
05/28/2024, 9:17 AMCaio Costa
05/28/2024, 11:01 AMPedro Francisco de Sousa Neto
05/29/2024, 2:37 PMCaio Costa
05/29/2024, 2:53 PMCaio Costa
05/29/2024, 3:36 PMsingleOf(::newInstance)
It is way cleaner and concise since I will only have one URL for the whole project, this is perfect
But since I need that default URL on the method's signature, would there be a way to tell Koin to skip that dependency and only inject the OkHttp Interceptor (In this specific case, but basically a way to ignore some dependencies even if it means an Annotation to do so)?
Thank you so much for your tip koinscrollPedro Francisco de Sousa Neto
05/29/2024, 5:04 PMCaio Costa
05/29/2024, 5:06 PM