e.ultra.kontainer.0.76.4.source-code.LazyServiceLookup.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kontainer Show documentation
Show all versions of kontainer Show documentation
"Kotlin Depdency Injection Framework"
package de.peekandpoke.ultra.kontainer
import de.peekandpoke.ultra.common.Lookup
import kotlin.reflect.KClass
/**
* Lazy [Lookup] implementation
*/
class LazyServiceLookup(
/** The kontainer */
private val kontainer: Kontainer,
/** The context */
private val context: InjectionContext,
/** Map from class to function that produces a service */
private val map: Map, (Kontainer, InjectionContext) -> T>,
) : Lookup {
val classes: Set> = map.keys
override fun has(cls: KClass): Boolean = map.contains(cls)
override fun get(cls: KClass): X = getOrNull(cls) ?: error("There is no service of type '$cls'")
@Suppress("UNCHECKED_CAST")
override fun getOrNull(cls: KClass): X? = map[cls]?.invoke(kontainer, context) as X?
override fun all(): List {
return classes.map { get(it) }
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy