@Module @InstallIn(SingletonComponent::class)

object AppEntryModule {

private val client = OkHttpClient.Builder().apply {
    addInterceptor(MyInterceptor(  ?????   ))
}.build()

@Provides
@Singleton
fun provideRetrofit(): Retrofit =
    Retrofit.Builder()
        .baseUrl(MOCK_URL)
        .client(client)
        .addConverterFactory(GsonConverterFactory.create())
        .build()

}

class MyInterceptor @Inject constructor( private val viewLifecycleOwner: LifecycleOwner ) : Interceptor { {}

1

There are 1 best solutions below

0
On

I found solution:

object AppEntryModule {

@Provides
@Singleton
fun provideRetrofit(@ApplicationContext appContext: Context): Retrofit {
    val client = OkHttpClient.Builder().apply {
        addInterceptor(MyInterceptor(MyPreferences(appContext)))
    }.build()
     return  Retrofit.Builder()
        .baseUrl(MOCK_URL)
        .client(client)
        .addConverterFactory(GsonConverterFactory.create())
        .build()
}