I have followed THIS tutorial for MVVM and Retrofit2 with Kodein structure/framework. I wanted to know, Using this same framework/structure how can i have multiple base URLs in a single App.
Below is the code of "MyApi" interface which have an interceptor class as parameter.
companion object {
operator fun invoke(
networkConnectionInterceptor: NetworkConnectionInterceptor
): MyApi {
val okkHttpclient = OkHttpClient.Builder()
.addInterceptor(networkConnectionInterceptor)
.readTimeout(20, TimeUnit.SECONDS)
.build()
return Retrofit.Builder()
.client(okkHttpclient)
.baseUrl("http://my-base-url")
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(MyApi::class.java)
}
}
And here is how Iam initializing MyApi interface in Application class:
bind() from singleton { PreferenceProvider(instance()) }
bind() from singleton { NetworkConnectionInterceptor(instance(), instance()) }
bind() from singleton { MyApi(instance()) }
Here instance() in MyApi is obviously NetworkConnectionInterceptor.
I have seen a lot of examples on stackoverflow and medium but i didnt got any help.