Reputation: 236
I was using Koin as dependency Injection library to create the ktor HttpClient:
val AppModule = module {
single { provideClientService() }
}
fun provideClientService(preferences: SharedPreferences): HttpClient {
install(Auth){
bearer {
loadTokens {
BearerTokens(sharedPreferences.getString("accessToken",""))
}
}
}}
but after the user login the accessToken is not updated.
I think it is because of the different scopes in koin. there is 3 kind of scopes in koin:
single definition : create an object that persists with the entire container lifetime (can't be dropped).
factory definition : create a new object each time. Short life. No persistence in the container (can't be shared).
scoped definition : create an object that is persistent tied to the associated scope lifetime.
so I changed the client definition to factory , because I want it to be updated after getting a new token. and now I wonder is it correct?
val AppModule = module {
factory { provideClientService() }
}
Upvotes: 0
Views: 1083