refactor(di): workaround unstable IntoSet ordering

EitherNet's ApiResultConverterFactory needs to go before any other
(de)serialization factories, but multibindings do not have ordering
guarantees. To fix this, I've changed the module to handle the EitherNet
configuration within api and let core continue supplying everything else.
This commit is contained in:
Harsh Shandilya 2022-11-13 17:52:15 +05:30
parent 8a4fee5f7c
commit 0bf60812e0
No known key found for this signature in database
3 changed files with 5 additions and 22 deletions

View file

@ -6,13 +6,14 @@
*/
package dev.msfjarvis.claw.api.injection
import com.slack.eithernet.ApiResultCallAdapterFactory
import com.slack.eithernet.ApiResultConverterFactory
import com.squareup.anvil.annotations.ContributesTo
import dagger.Module
import dagger.Provides
import dev.msfjarvis.claw.api.LobstersApi
import dev.msfjarvis.claw.injection.scopes.AppScope
import okhttp3.OkHttpClient
import retrofit2.CallAdapter
import retrofit2.Converter
import retrofit2.Retrofit
import retrofit2.create
@ -24,15 +25,13 @@ object ApiModule {
fun provideRetrofit(
client: OkHttpClient,
converterFactories: Set<@JvmSuppressWildcards Converter.Factory>,
callAdapterFactories: Set<@JvmSuppressWildcards CallAdapter.Factory>
): Retrofit {
return Retrofit.Builder()
.client(client)
.baseUrl(LobstersApi.BASE_URL)
.apply {
converterFactories.forEach(this::addConverterFactory)
callAdapterFactories.forEach(this::addCallAdapterFactory)
}
.addConverterFactory(ApiResultConverterFactory)
.addCallAdapterFactory(ApiResultCallAdapterFactory)
.apply { converterFactories.forEach(this::addConverterFactory) }
.build()
}