Last active
September 9, 2020 16:33
-
-
Save rygelouv/e1343974c88e505cf2139e2bd508453b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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