Joan Colmenero
11/20/2019, 12:52 PMRetrofit
as :
val retrofitModule = Kodein.Module("retrofitModule") {
bind<OkHttpClient>() with singleton {
OkHttpClient()
.newBuilder()
.addInterceptor(HeadersInterceptor())
.addInterceptor(HttpLoggingInterceptor().apply {
level = if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BASIC else HttpLoggingInterceptor.Level.NONE
})
.build()
}
bind<Retrofit>() with singleton {
Retrofit.Builder()
.baseUrl("realbaseurl")
.client(instance())
.addConverterFactory(GsonConverterFactory.create())
.build()
}
bind<MyService>() with singleton {
instance<Retrofit>().create(MyService::class.java)
}
}
but now I want to start using MockWebServer
and I saw that I have to create a "Fake retrofit" with the baseUrl
as "/"
, so I'm wondering if I create a fakeRetrofitModule
how can I get the instance of that Retrofit
since I have two, now.
val fakeRetrofitModule = Kodein.Module("fakeRetrofitModule") {
bind<Retrofit>() with singleton {
Retrofit.Builder()
.baseUrl("/")
.client(instance())
.addConverterFactory(GsonConverterFactory.create())
.build()
}
bind<MyService>() with singleton {
instance<Retrofit>().create(MyService::class.java)
}
}
Any idea?