mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-18 14:47:15 +00:00
lazyInject
This commit is contained in:
parent
c2ec73c70a
commit
999c8327bd
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
## 0.18.4
|
## 0.18.4
|
||||||
|
|
||||||
|
* `Koin`:
|
||||||
|
* New extension `lazyInject`
|
||||||
|
|
||||||
## 0.18.3
|
## 0.18.3
|
||||||
|
|
||||||
* `Versions`:
|
* `Versions`:
|
||||||
|
27
koin/src/jvmMain/kotlin/LazyInject.kt
Normal file
27
koin/src/jvmMain/kotlin/LazyInject.kt
Normal 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)
|
Loading…
Reference in New Issue
Block a user