Package-level declarations

Types

Link copied to clipboard
typealias Key<T> = ServiceKey<T, *, *, *>

A Key type used in ServiceLocator. Will provide values of type T.

Link copied to clipboard
abstract class ServiceLocator @JvmOverloads constructor(allowReregister: Boolean = false)

A basic service locator for storing common dependencies. ServiceLocator acts like a heterogeneous map, holding values of different types. The ServiceKey dictates which type will be accessed.

Functions

Link copied to clipboard
inline fun <T : Any> classKey(): LazyKey<T>

Creates a LazyClassKey for the reified type T, which can be used for class-based lookups.

Link copied to clipboard
inline fun <T : Any> ServiceLocator.get(): T

A convenience extension to fetch a singleton instance from the ServiceLocator using its reified type T as the key.

fun <T : Any> ServiceLocator.get(key: ServiceKey<T, *, Unit, *>): T

Fetches an item for key. If no provider has been registered, this will delegate to ServiceLocator.onMiss.

Link copied to clipboard
inline fun <T : Any> ServiceLocator.getOrNull(): T?

A convenience extension to fetch a singleton instance from the ServiceLocator using its reified type T as the key.

fun <T : Any> ServiceLocator.getOrNull(key: ServiceKey<T, *, Unit, *>): T?

Fetches the item for key. If no provider has been registered, returns null. Does not invoke ServiceLocator.onMiss.