FactoryKey

A ServiceKey that creates a new instance of a service every time one is requested.

This key is useful for services that are lightweight and should not be shared, or for services whose creation depends on parameters that are only available at runtime. When registering a FactoryKey, you provide a factory lambda. This lambda is executed on every get() call.

Parameters

T

The type of object to be produced by the factory.

GetParams

The type of parameters to be passed to the factory lambda during retrieval. Use Unit if no parameters are needed.

Constructors

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

Types

Link copied to clipboard
class Entry<T, GetParams>(factory: (GetParams) -> T) : ServiceEntry<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: (GetParams) -> T): FactoryKey.Entry<T, GetParams>

Creates an Entry to provide values.

Link copied to clipboard
open override fun getValue(params: GetParams, 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.