SingletonKey

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

A ServiceKey for a pre-instantiated, eagerly-loaded service.

This key is intended for services that you want to create and register at the same time, typically during the initial setup of your ServiceLocator. When you register a SingletonKey using put(), you provide the actual service instance directly. That instance is then stored and returned for all subsequent requests.

While it is possible to use this key with a late-registration function like getOrProvide(), doing so negates the eager-loading aspect of this key. For lazy-loading behavior, LazyKey is the more appropriate choice.

Inheritors

Constructors

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

Types

Link copied to clipboard
class Entry<T>(val service: T) : ParamlessServiceEntry<T>

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: T): SingletonKey.Entry<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.