У меня есть 2 модифицированных клиента, один из них по умолчанию, а второй имеет различную реализацию, например (базовый URL, перехватчики и т. Д.)
Мне нужно внедрить клиента по умолчанию, не используя ссылку на имя
первый клиент: -
single<Retrofit> {
Retrofit.Builder()
.baseUrl(RemoteConstants.BASE_URL)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(APIResponseConverter())
.addConverterFactory(GsonConverterFactory.create(get()))
.client(get())
.build()
}
второй клиент: -
single<Retrofit>("retrofit_second") {
Retrofit.Builder()
.baseUrl("diffrent url")
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create(get()))
.client(get("SecondOkHttpClient"))
.build()
}
Мой способ ввода
val myModule = module {
factory { get<Retrofit>().create(FirstAPI::class.java) } // Why Koin did not figure it without providing its default name !?
factory { get<Retrofit>("retrofit_second").create(SecondAPI::class.java) }
factory<IMyRemoteDataSource> { MyRemoteDataSource(get(), get()) }
factory<IMyRepository> { MyRepository(get()) }
factory { MyUseCase(get()) }
}
результат:
Multiple definitions found for type 'class retrofit2.Retrofit' - Koin can't choose between :
Single [name='retrofit_second',class='retrofit2.Retrofit']
Single [name='Retrofit',class='retrofit2.Retrofit']
Почему Koin не получил экземпляр Retrofit по умолчанию, не указав его имя по умолчанию (Retrofit)!?
factory { get<Retrofit>().create(FirstAPI::class.java) }