lazyInject

This commit is contained in:
InsanusMokrassar 2023-05-14 16:36:24 +06:00
parent c2ec73c70a
commit 999c8327bd
2 changed files with 30 additions and 0 deletions

View File

@ -2,6 +2,9 @@
## 0.18.4
* `Koin`:
* New extension `lazyInject`
## 0.18.3
* `Versions`:

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)