Koin: Can't create definition for 'Single. due to error : No compatible definition found.

Created on 21 Dec 2018  路  3Comments  路  Source: InsertKoinIO/koin

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

}
question

Most helpful comment

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

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hkelidari picture hkelidari  路  3Comments

miladsalimiiii picture miladsalimiiii  路  3Comments

TedHoryczun picture TedHoryczun  路  4Comments

LukasAnda picture LukasAnda  路  3Comments

ILAgent picture ILAgent  路  3Comments