Skip to content

Commit

Permalink
Add RequestScope UUID to avoid collision over local hashcode
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgiuliani committed Sep 13, 2024
1 parent 4ec6cf0 commit 6f48c39
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fun main(args: Array<String>) {
fun Application.mainModule() {
install(CallLogging)
install(Koin) {
slf4jLogger(Level.INFO)
printLogger(Level.DEBUG)
modules(appModule)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package org.koin.core.component

import org.koin.core.qualifier.TypeQualifier
import org.koin.core.scope.Scope
import org.koin.core.scope.ScopeID
import org.koin.ext.getFullName

/**
Expand All @@ -34,6 +35,10 @@ interface KoinScopeComponent : KoinComponent {
fun <T : Any> T.getScopeId() = this::class.getFullName() + "@" + this.hashCode()
fun <T : Any> T.getScopeName() = TypeQualifier(this::class)

fun <T : KoinScopeComponent> T.createScope(scopeId : ScopeID, source: Any? = null): Scope {
return getKoin().createScope(scopeId, getScopeName(), source)
}

fun <T : KoinScopeComponent> T.createScope(source: Any? = null): Scope {
return getKoin().createScope(getScopeId(), getScopeName(), source)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ package org.koin.ktor.plugin
import org.koin.core.Koin
import org.koin.core.component.KoinScopeComponent
import org.koin.core.component.createScope
import org.koin.mp.KoinPlatformTools
import org.koin.mp.generateId

/**
* Request Scope Holder
*
* @author Arnaud Giuliani
*/
class RequestScope(private val _koin: Koin) : KoinScopeComponent {
private val scopeId = "request_"+KoinPlatformTools.generateId()
override fun getKoin(): Koin = _koin
override val scope = createScope()
override val scope = createScope(scopeId = scopeId)
}

0 comments on commit 6f48c39

Please sign in to comment.