ScopedServiceLocator

open class ScopedServiceLocator<out S> @JvmOverloads constructor(val scope: S, allowReregister: Boolean = false) : ServiceLocator

A ServiceLocator that is associated with a specific scope.

The scope acts as a label to identify the environment in which the locator is operating (e.g., Production, Testing). This allows for conditional service registration based on the current context.

Parameters

S

The type of the scope identifier.

scope

The specific scope instance for this locator.

allowReregister

if true, allow registering keys multiple times. The latest registration will be used. This should generally only be true for tests.

See also

Constructors

Link copied to clipboard
constructor(scope: S, allowReregister: Boolean = false)

Properties

Link copied to clipboard
val scope: S

Functions

Link copied to clipboard
fun <T : Any, GetParams> get(key: ServiceKey<T, *, GetParams, *>, params: GetParams): T
Link copied to clipboard
fun <T : Any, GetParams> getOrNull(key: ServiceKey<T, *, GetParams, *>, params: GetParams): T?
Link copied to clipboard
inline fun <T : Any> getOrProvide(noinline allowedScopes: (S) -> Boolean, threadSafetyMode: LazyThreadSafetyMode = defaultLazyKeyThreadSafetyMode, noinline provider: () -> T): T

Fetches an item for the given reified type T.

fun <T : Any, GetParams, PutParams> getOrProvide(key: ServiceKey<T, *, GetParams, PutParams>, allowedScopes: (S) -> Boolean, putParams: PutParams, getParams: GetParams): T

Fetches an item for the given key.

Link copied to clipboard
fun <S, T : Any, PutParams> ScopedServiceLocator<S>.getOrProvide(key: ServiceKey<T, *, Unit, PutParams>, allowedScopes: (S) -> Boolean, putParams: PutParams): T
fun <S, T : Any> ScopedServiceLocator<S>.getOrProvide(key: LazyKey<T>, allowedScopes: (S) -> Boolean, threadSafetyMode: LazyThreadSafetyMode = defaultLazyKeyThreadSafetyMode, provider: () -> T): T

Fetches an item for the given key.

Link copied to clipboard
open fun <T : Any, PutParams> onInvalidScope(key: ServiceKey<T, *, *, PutParams>, putParams: PutParams): ServiceEntry<T>

Called when getOrProvide is attempted for a key in a disallowed scope.

Link copied to clipboard
fun <T : Any, PutParams> put(key: ServiceKey<T, *, *, PutParams>, params: PutParams)