Skip to content

Instantly share code, notes, and snippets.

@rygelouv
Last active September 9, 2020 16:33
Show Gist options
  • Save rygelouv/e1343974c88e505cf2139e2bd508453b to your computer and use it in GitHub Desktop.
Save rygelouv/e1343974c88e505cf2139e2bd508453b to your computer and use it in GitHub Desktop.
inline fun <reified T: Any> get(): T {
val declaration = declarationRegistry[T::class]
var instance = declaration?.invoke()
if (instance == null) {
val liteKoin = LiteKoinContext.getLiteKoin()
instance = liteKoin.declarations[T::class]?.invoke() ?: error("Unable to find declaration of type ${T::class.qualifiedName}")
}
return instance as T
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment