MicroUtils/koin/src/jvmMain/kotlin/FactoryWithBinds.kt

29 lines
962 B
Kotlin
Raw Normal View History

2022-09-14 16:14:20 +00:00
package dev.inmo.micro_utils.koin
import org.koin.core.definition.Definition
2023-02-05 11:45:45 +00:00
import org.koin.core.definition.KoinDefinition
2022-09-14 16:14:20 +00:00
import org.koin.core.instance.InstanceFactory
import org.koin.core.module.Module
import org.koin.core.qualifier.Qualifier
import org.koin.dsl.binds
import kotlin.reflect.KClass
import kotlin.reflect.full.allSuperclasses
inline fun <reified T : Any> Module.factoryWithBinds(
qualifier: Qualifier? = null,
bindFilter: (KClass<*>) -> Boolean = { true },
noinline definition: Definition<T>
2023-02-05 11:45:45 +00:00
): KoinDefinition<*> {
2022-09-14 16:14:20 +00:00
return factory(qualifier, definition) binds (T::class.allSuperclasses.filter(bindFilter).toTypedArray())
}
inline fun <reified T : Any> Module.factoryWithBinds(
qualifier: String,
bindFilter: (KClass<*>) -> Boolean = { true },
noinline definition: Definition<T>
2023-02-05 11:45:45 +00:00
): KoinDefinition<*> {
2022-09-14 16:14:20 +00:00
return factory(qualifier, definition) binds (T::class.allSuperclasses.filter(bindFilter).toTypedArray())
}