LazyKey

open class LazyKey<T : Any>(val type: KClass<T>) : ServiceKey<T, LazyKey.Entry<T, T>, Unit, LazyKey.PutParams<T>>

A ServiceKey for services that are created and stored lazily.

The provider lambda is executed only the first time a value for this key is requested from the ServiceLocator. The resulting instance is then stored and returned for all subsequent requests for the same key. The multi-thread initialization behavior is determined by the LazyThreadSafetyMode.

Inheritors

Constructors

Link copied to clipboard
constructor(type: KClass<T>)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
inner class Entry<T : Any>(loader: () -> T, threadSafetyMode: LazyThreadSafetyMode) : ParamlessServiceEntry<T>

The ServiceEntry for a LazyKey. It holds the provider lambda and the created service.

Link copied to clipboard
class PutParams<T>(val provider: () -> T, val threadSafetyMode: LazyThreadSafetyMode)

Properties

Link copied to clipboard
open override val type: KClass<T>

A reference to the type provided by this key.

Functions

Link copied to clipboard
open override fun createEntry(params: LazyKey.PutParams<T>): LazyKey.Entry<T, T>

Creates an Entry to provide values.

Link copied to clipboard
open override fun getValue(params: Unit, entry: ServiceEntry<T>): T

Retrieve the value from entry. The entry will have been created by a ServiceKey that is equals to this key. If this ServiceKey is only equals to other keys of the same class, then entry will be guaranteed to be of type Entry.

Link copied to clipboard
open override fun toString(): String