put

inline fun <T : Any> ServiceLocator.put(threadSafetyMode: LazyThreadSafetyMode = defaultLazyKeyThreadSafetyMode, noinline provider: () -> T)

Registers a lazy singleton provider using a LazyClassKey for the reified type T.

The provider will be invoked only the first time a value is requested for the type T. The created instance is then stored and reused for all subsequent requests.

Parameters

T

The service type to register.

threadSafetyMode

The LazyThreadSafetyMode for the initialization.

provider

A lambda that creates the service instance.


inline fun <T : Any> ServiceLocator.put(value: T)

Registers an eager singleton instance using a SingletonClassKey for the reified type T.

The provided value is stored directly and will be returned for all subsequent requests for the type T.

Parameters

T

The service type to register.

value

The service instance to store.


fun <T : Any> ServiceLocator.put(key: LazyKey<T>, threadSafetyMode: LazyThreadSafetyMode = getDefaultParams().threadSafetyMode, provider: () -> T)

Registers a lazy singleton provider for the given key.

The provider lambda will be invoked only the first time a value is requested for this key. The created instance will be stored and reused for all subsequent requests.

By default, it is an error to register the same key more than once.

Parameters

key

The LazyKey to associate with the provider.

threadSafetyMode

The LazyThreadSafetyMode for the initialization.

provider

A lambda that creates the service instance.