是否可以只从 a 读取/写入原始类型DataStore?例如,我只想阅读一个Int. 我不想让任何东西Flow包裹在它周围。只是简单Int。
我使用 Koin 作为我的应用程序的 DI。我创建了一个模块:
object NetworkModule {
fun get() = module {
single {
val authenticationInterceptor = Interceptor { chain ->
// Request customization goes here
}
OkHttpClient.Builder()
.connectTimeout(15, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.addInterceptor(authenticationInterceptor) //Not all clients might have this interceptor
.build()
}
single {
Retrofit.Builder()
.baseUrl("example.com")
.client(get(/* I would like to send some paramter here */))
.addConverterFactory(GsonConverterFactory.create(get()))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()
.create(Api::class.java)
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何创建不同的HttpClient或Retrofit具有不同参数集或具有不同实例化的实例?例如,在某些情况下,我可能需要使用它OkHttpClient,AutheniticationInterceptor而在其他一些情况下,我的客户可能不需要使用它。
get()我可以在调用时传递一些参数以便获得不同的实例吗?任何建议都会受到赞赏。