@模块@InstallIn(SingletonComponent::class(
对象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构造函数(private val view生命周期所有者:生命周期所有者):拦截器{{}
我找到了解决方案:
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()
}