alsoInvalidate, alsoDoInvalidate, singleSuspend, factorySuspend

This commit is contained in:
2025-03-14 14:13:58 +06:00
parent a4c6c367e3
commit 831bf44e34
6 changed files with 86 additions and 2 deletions

View File

@@ -0,0 +1,32 @@
package dev.inmo.micro_utils.koin
import dev.inmo.micro_utils.coroutines.doSynchronously
import kotlinx.coroutines.CoroutineScope
import org.koin.core.module.Module
import org.koin.core.parameter.ParametersHolder
import org.koin.core.qualifier.Qualifier
import org.koin.core.qualifier.StringQualifier
import org.koin.core.scope.Scope
import kotlin.reflect.KClass
inline fun <reified T : Any> Module.factorySuspend(
qualifier: Qualifier? = null,
coroutineScope: CoroutineScope? = null,
noinline definition: suspend Scope.(ParametersHolder) -> T
) = factory(
qualifier,
if (coroutineScope == null) {
{
doSynchronously {
definition(it)
}
}
} else {
{
coroutineScope.doSynchronously {
definition(it)
}
}
}
)

View File

@@ -0,0 +1,32 @@
package dev.inmo.micro_utils.koin
import dev.inmo.micro_utils.coroutines.doSynchronously
import kotlinx.coroutines.CoroutineScope
import org.koin.core.module.Module
import org.koin.core.parameter.ParametersHolder
import org.koin.core.qualifier.StringQualifier
import org.koin.core.scope.Scope
inline fun <reified T : Any> Module.singleSuspend(
qualifier: StringQualifier,
createdAtStart: Boolean = false,
coroutineScope: CoroutineScope? = null,
noinline definition: suspend Scope.(ParametersHolder) -> T
) = single(
qualifier,
createdAtStart,
if (coroutineScope == null) {
{
doSynchronously {
definition(it)
}
}
} else {
{
coroutineScope.doSynchronously {
definition(it)
}
}
}
)