Merge pull request #256 from InsanusMokrassar/0.18.4

0.18.4
This commit is contained in:
InsanusMokrassar 2023-05-14 16:51:57 +06:00 committed by GitHub
commit a067cb0c0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 2 deletions

View File

@ -1,5 +1,10 @@
# Changelog
## 0.18.4
* `Koin`:
* New extension `lazyInject`
## 0.18.3
* `Versions`:

View File

@ -14,5 +14,5 @@ crypto_js_version=4.1.1
# Project data
group=dev.inmo
version=0.18.3
android_code_version=194
version=0.18.4
android_code_version=195

View File

@ -0,0 +1,27 @@
package dev.inmo.micro_utils.koin
import org.koin.core.parameter.ParametersDefinition
import org.koin.core.qualifier.Qualifier
import org.koin.java.KoinJavaComponent
import kotlin.reflect.KClass
fun <T> lazyInject(
kClassFactory: () -> KClass<*>,
qualifier: Qualifier? = null,
parameters: ParametersDefinition? = null
): Lazy<T> {
return lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
KoinJavaComponent.get(kClassFactory().java, qualifier, parameters)
}
}
fun <T> lazyInject(
kClass: KClass<*>,
qualifier: Qualifier? = null,
parameters: ParametersDefinition? = null
): Lazy<T> = lazyInject({ kClass }, qualifier, parameters)
inline fun <reified T> lazyInject(
qualifier: Qualifier? = null,
noinline parameters: ParametersDefinition? = null
): Lazy<T> = lazyInject(T::class, qualifier, parameters)