I have an issue when I try to provide Ktor’s
HttpClient
instance using Koin. Here’s my code:
single {
val buildVariant: BuildVariant = get()
val httpClientEngine: HttpClientEngine = get()
val kotlinxSerializer: KotlinxSerializer = get()
val tokenRefresher: TokenRefresher = get()
HttpClient(httpClientEngine) {
install(JsonFeature) {
serializer = kotlinxSerializer
}
install(Logging) {
...
}
install(HttpSend) {
intercept { clientCall, requestBuilder ->
...
requestBuilder.takeFrom(clientCall.request)
val newAccessToken = tokenRefresher.refreshToken()
requestBuilder.setAuthorizationHeader(newAccessToken)
execute(requestBuilder)
}
}
}
}
The problem is in this line:
val newAccessToken = tokenRefresher.refreshToken()
I get
kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen org.koin.core.scope.Scope
Can someone please explain why do I get this exception if I’m not trying to modify
tokenRefresher
?
refreshToken
is a suspending function, but for the debugging purposes, I made it a regular function which returns some string constant. The behavior is the same, I still get the same exception.
I’m using Ktor version
1.5.2