commonMain.org.kodein.di.internal.DirectDIImpl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kodein-di-js Show documentation
Show all versions of kodein-di-js Show documentation
KODEIN Dependency Injection Core
package org.kodein.di.internal
import org.kodein.di.*
import org.kodein.type.TypeToken
@Suppress("UNCHECKED_CAST")
private inline val DIContext<*>.anyType get() = type as TypeToken
@Suppress("FunctionName")
internal abstract class DirectDIBaseImpl protected constructor(override val container: DIContainer, val context: DIContext<*>) : DirectDI {
override val directDI: DirectDI get() = this
override val lazy: DI get() = DIImpl(container as DIContainerImpl).On(context = context)
override fun On(context: DIContext<*>): DirectDI = DirectDIImpl(container, context)
override fun Factory(argType: TypeToken, type: TypeToken, tag: Any?): (A) -> T = container.factory(DI.Key(context.anyType, argType, type, tag), context.value)
override fun FactoryOrNull(argType: TypeToken, type: TypeToken, tag: Any?): ((A) -> T)? = container.factoryOrNull(DI.Key(context.anyType, argType, type, tag), context.value)
override fun Provider(type: TypeToken, tag: Any?): () -> T = container.provider(DI.Key(context.anyType, TypeToken.Unit, type, tag), context.value)
override fun Provider(argType: TypeToken, type: TypeToken, tag: Any?, arg: () -> A): () -> T = container.factory(DI.Key(context.anyType, argType, type, tag), context.value).toProvider(arg)
override fun ProviderOrNull(type: TypeToken, tag: Any?): (() -> T)? = container.providerOrNull(DI.Key(context.anyType, TypeToken.Unit, type, tag), context.value)
override fun ProviderOrNull(argType: TypeToken, type: TypeToken, tag: Any?, arg: () -> A): (() -> T)? = container.factoryOrNull(DI.Key(context.anyType, argType, type, tag), context.value)?.toProvider(arg)
override fun Instance(type: TypeToken, tag: Any?): T = container.provider(DI.Key(context.anyType, TypeToken.Unit, type, tag), context.value).invoke()
override fun Instance(argType: TypeToken, type: TypeToken, tag: Any?, arg: A): T = container.factory(DI.Key(context.anyType, argType, type, tag), context.value).invoke(arg)
override fun InstanceOrNull(type: TypeToken, tag: Any?): T? = container.providerOrNull(DI.Key(context.anyType, TypeToken.Unit, type, tag), context.value)?.invoke()
override fun InstanceOrNull(argType: TypeToken, type: TypeToken, tag: Any?, arg: A): T? = container.factoryOrNull(DI.Key(context.anyType, argType, type, tag), context.value)?.invoke(arg)
}
internal expect class DirectDIImpl(container: DIContainer, context: DIContext<*>) : DirectDI
© 2015 - 2024 Weber Informatics LLC | Privacy Policy