getOrProvide

inline fun <T : Any> SimpleServiceLocator<ServiceLocatorScope>.getOrProvide(threadSafetyMode: LazyThreadSafetyMode = defaultThreadSafetyMode, noinline provider: (ServiceLocatorScope) -> T): T

Fetches the singleton instance for the reified type T.

If an instance has not been previously registered, it creates and stores a new one using the provider lambda. This provider is only active in the ServiceLocatorScope.Production scope; in other scopes, this delegates to the locator's onInvalidScope behavior.

Parameters

T

The service type to retrieve.

threadSafetyMode

The thread safety mode for the lazy initialization.

provider

A lambda that creates the service instance if one doesn't exist.

See also