Registry

object Registry

Services registry for decoupling SDK components Acts as a very basic Service Locator for internal SDK dependencies

Core dependencies are defined as properties for ease of access. Dynamic dependencies can be defined and fetched with the add/get methods. At this time I treat all our services as singletons

Technical note on the dynamic registry methods:

  • noinline keyword allows us to store the Registration lambdas

  • inline methods make it possible to use generics properly here

  • @PublishedApi is required so that the inlined methods can read/write to private registry without leaving the type-erased methods fully public

Functions

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

Get a registered service by type

Link copied to clipboard
inline fun <T : Any> isRegistered(): Boolean

Query whether a service of type is already registered

Link copied to clipboard
inline fun <T : Any> register(service: Any)

Register a service for a type, specified by generic parameter Typical usage would be to register the singleton implementation of an interface

inline fun <T : Any> register(noinline registration: Registration)

Lazily register a service builder for a type, specified by generic parameter Typical usage would be to register a builder method for the implementation of an interface

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val log: Log
Link copied to clipboard