mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-18 14:47:15 +00:00
add RandomQualifier
This commit is contained in:
parent
1e1f7df86d
commit
2696e663cf
@ -1,10 +1,7 @@
|
|||||||
package dev.inmo.micro_utils.koin
|
package dev.inmo.micro_utils.koin
|
||||||
|
|
||||||
import com.benasher44.uuid.uuid4
|
|
||||||
import org.koin.core.definition.Definition
|
import org.koin.core.definition.Definition
|
||||||
import org.koin.core.instance.InstanceFactory
|
|
||||||
import org.koin.core.module.Module
|
import org.koin.core.module.Module
|
||||||
import org.koin.core.qualifier.StringQualifier
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will be useful in case you need to declare some singles with one type several types, but need to separate them and do
|
* Will be useful in case you need to declare some singles with one type several types, but need to separate them and do
|
||||||
@ -12,4 +9,4 @@ import org.koin.core.qualifier.StringQualifier
|
|||||||
*/
|
*/
|
||||||
inline fun <reified T : Any> Module.factoryWithRandomQualifier(
|
inline fun <reified T : Any> Module.factoryWithRandomQualifier(
|
||||||
noinline definition: Definition<T>
|
noinline definition: Definition<T>
|
||||||
) = factory(uuid4().toString(), definition)
|
) = factory(RandomQualifier(), definition)
|
||||||
|
6
koin/src/commonMain/kotlin/RandomQualifier.kt
Normal file
6
koin/src/commonMain/kotlin/RandomQualifier.kt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package dev.inmo.micro_utils.koin
|
||||||
|
|
||||||
|
import com.benasher44.uuid.uuid4
|
||||||
|
import org.koin.core.qualifier.StringQualifier
|
||||||
|
|
||||||
|
fun RandomQualifier(randomFun: () -> String = { uuid4().toString() }) = StringQualifier(randomFun())
|
@ -1,10 +1,7 @@
|
|||||||
package dev.inmo.micro_utils.koin
|
package dev.inmo.micro_utils.koin
|
||||||
|
|
||||||
import com.benasher44.uuid.uuid4
|
|
||||||
import org.koin.core.definition.Definition
|
import org.koin.core.definition.Definition
|
||||||
import org.koin.core.instance.InstanceFactory
|
|
||||||
import org.koin.core.module.Module
|
import org.koin.core.module.Module
|
||||||
import org.koin.core.qualifier.StringQualifier
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will be useful in case you need to declare some singles with one type several types, but need to separate them and do
|
* Will be useful in case you need to declare some singles with one type several types, but need to separate them and do
|
||||||
@ -13,4 +10,4 @@ import org.koin.core.qualifier.StringQualifier
|
|||||||
inline fun <reified T : Any> Module.singleWithRandomQualifier(
|
inline fun <reified T : Any> Module.singleWithRandomQualifier(
|
||||||
createdAtStart: Boolean = false,
|
createdAtStart: Boolean = false,
|
||||||
noinline definition: Definition<T>
|
noinline definition: Definition<T>
|
||||||
) = single(uuid4().toString(), createdAtStart, definition)
|
) = single(RandomQualifier(), createdAtStart, definition)
|
||||||
|
@ -1,16 +1,13 @@
|
|||||||
package dev.inmo.micro_utils.koin
|
package dev.inmo.micro_utils.koin
|
||||||
|
|
||||||
import com.benasher44.uuid.uuid4
|
|
||||||
import org.koin.core.definition.Definition
|
import org.koin.core.definition.Definition
|
||||||
import org.koin.core.instance.InstanceFactory
|
import org.koin.core.instance.InstanceFactory
|
||||||
import org.koin.core.module.Module
|
import org.koin.core.module.Module
|
||||||
import org.koin.dsl.binds
|
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.reflect.full.allSuperclasses
|
|
||||||
|
|
||||||
inline fun <reified T : Any> Module.factoryWithRandomQualifierAndBinds(
|
inline fun <reified T : Any> Module.factoryWithRandomQualifierAndBinds(
|
||||||
bindFilter: (KClass<*>) -> Boolean = { true },
|
bindFilter: (KClass<*>) -> Boolean = { true },
|
||||||
noinline definition: Definition<T>
|
noinline definition: Definition<T>
|
||||||
): Pair<Module, InstanceFactory<*>> {
|
): Pair<Module, InstanceFactory<*>> {
|
||||||
return factoryWithBinds(uuid4().toString(), bindFilter, definition)
|
return factoryWithBinds(RandomQualifier(), bindFilter, definition)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package dev.inmo.micro_utils.koin
|
package dev.inmo.micro_utils.koin
|
||||||
|
|
||||||
import com.benasher44.uuid.uuid4
|
|
||||||
import org.koin.core.definition.Definition
|
import org.koin.core.definition.Definition
|
||||||
import org.koin.core.instance.InstanceFactory
|
import org.koin.core.instance.InstanceFactory
|
||||||
import org.koin.core.module.Module
|
import org.koin.core.module.Module
|
||||||
@ -11,5 +10,5 @@ inline fun <reified T : Any> Module.singleWithRandomQualifierAndBinds(
|
|||||||
bindFilter: (KClass<*>) -> Boolean = { true },
|
bindFilter: (KClass<*>) -> Boolean = { true },
|
||||||
noinline definition: Definition<T>
|
noinline definition: Definition<T>
|
||||||
): Pair<Module, InstanceFactory<*>> {
|
): Pair<Module, InstanceFactory<*>> {
|
||||||
return singleWithBinds(uuid4().toString(), createdAtStart, bindFilter, definition)
|
return singleWithBinds(RandomQualifier(), createdAtStart, bindFilter, definition)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user