e.ultra.kontainer.0.77.0.source-code.InjectionContext.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"
The newest version!
package de.peekandpoke.ultra.kontainer
import kotlin.reflect.KClass
/**
* The injection context as passed through to all parameter providers.
*
* It carries
* - the current [kontainer] instances
* - the service that is injecting: [injectingClass]
* - the service that is requesting a service: [requestingClass]
*/
data class InjectionContext internal constructor(
/** Class requesting the service */
val requestingClass: KClass,
/** Class that is about to be injected */
val injectingClass: KClass,
) {
companion object {
internal val kontainerRoot = InjectionContext(Kontainer::class, Kontainer::class)
}
private val nextCache = mutableMapOf, InjectionContext>()
/**
* Advances the context.
*
* Makes the [injectingClass] the [requestingClass]
* Makes the passed in [nextInjectingClass] the [injectingClass]
*/
internal fun next(nextInjectingClass: KClass): InjectionContext {
return nextCache.getOrPut(nextInjectingClass) {
InjectionContext(
requestingClass = injectingClass,
injectingClass = nextInjectingClass
)
}
}
// /**
// * Gets a config parameter from the kontainer
// */
// internal fun getConfig(name: String): T = kontainer.getConfig(name)
//
// /**
// * Gets a service from the kontainer
// */
// internal fun get(cls: KClass): T = kontainer.get(cls, this)
//
// /**
// * Gets a service or null from the kontainer
// */
// internal fun getOrNull(cls: KClass): T? = kontainer.getOrNull(cls, this)
//
// /**
// * Gets all supertype services for the given [cls] as a List
// */
// internal fun getAll(cls: KClass): List = kontainer.getAll(cls, this)
//
// /**
// * Gets all supertype services for the given [cls] as a Lookup
// */
// internal fun getLookup(cls: KClass): LazyServiceLookup = kontainer.getLookup(cls, this)
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy