class KoinCoreModule {
val koinCoreModule = module {
single<ISharedPreferenceService>( definition = { SharedPreferenceImp(androidApplication()) })
single<ICalendarService>( definition = { CalendarImp(androidApplication()) })
single<IDateTimePickerService>( definition = { DateTimePickerImp(androidApplication()) })
single<Interceptor> ( definition = { ApiInterceptor(get())})
single<IVNSystemClientBuilder> { VNSystemClientBuilder(get()) }
single<IVNSystemClient> {VNSystemClient(get())}
}
}
getting error when using get() in other dependency. please do needful
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nailsalon/com.vns.salon.screens.welcomeScreen.WelcomeActivity}: org.koin.error.BeanInstanceCreationException: Can't create definition for 'Single [name='IVNSystemClientBuilder',class='com.vns.salon.remote.client.IVNSystemClientBuilder']' due to error :
No compatible definition found. Check your module definition
class VNSystemClientBuilder(apiInterceptor:ApiInterceptor) :KoinComponent, IVNSystemClientBuilder {
private val API_BASE_URL = BuildConfig.HOST
private val CONNECT_TIMEOUT = 15
private val READ_TIMEOUT = 60
private val WRITE_TIMEOUT = 60
private val httpLoggingInterceptor = HttpLoggingInterceptor()
private val builder = Retrofit.Builder()
.baseUrl(API_BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
private val client: OkHttpClient = OkHttpClient.Builder()
.connectTimeout(CONNECT_TIMEOUT.toLong(), TimeUnit.SECONDS)
.writeTimeout(WRITE_TIMEOUT.toLong(), TimeUnit.SECONDS)
.readTimeout(READ_TIMEOUT.toLong(), TimeUnit.SECONDS)
.addInterceptor(httpLoggingInterceptor)
.addInterceptor(apiInterceptor)
.hostnameVerifier { _, _ -> true }
.build()
private val retrofit: Retrofit = builder.client(client).build()
init {
if (BuildConfig.DEBUG) {
httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
} else {
httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.BASIC
}
}
override fun getClient() = client
override fun getBuilder() = builder
override fun getRetrofit()= retrofit
}
I get a similar error. Any solution found or mistake that can be corrected?.
it's because it doesnt found your definition for ApiInterceptor.
Your definition single<Interceptor> { ApiInterceptor(get())} only bind Interceptor type. To bind several types use: single { ApiInterceptor(get())} bind Interceptor::class
@arnaudgiuliani thank you that definitely was my problem too.
Most helpful comment
it's because it doesnt found your definition for
ApiInterceptor.Your definition
single<Interceptor> { ApiInterceptor(get())}only bindInterceptortype. To bind several types use:single { ApiInterceptor(get())} bind Interceptor::class