
com.freya02.botcommands.internal.InterfacedServiceProperty.kt Maven / Gradle / Ivy
package com.freya02.botcommands.internal
import com.freya02.botcommands.api.core.service.ServiceContainer
import com.freya02.botcommands.api.core.service.getServiceOrNull
import mu.KotlinLogging
internal inline fun ServiceContainer.interfacedService(crossinline defaultSupplier: () -> U): Lazy {
val logger = KotlinLogging.logger { }
return lazy {
(getServiceOrNull() ?: defaultSupplier()).also { service ->
logger.debug { "Found an instance of interfaced service ${T::class.simpleName} (${service::class.simpleNestedName})" }
}
}
}
internal inline fun ServiceContainer.nullableInterfacedService(): Lazy {
val logger = KotlinLogging.logger { }
return lazy {
getServiceOrNull().also { service ->
if (service != null) {
logger.debug { "Found an instance of interfaced service ${T::class.simpleNestedName} (${service::class.simpleNestedName})" }
} else {
logger.debug { "Found no instance of interfaced service ${T::class.simpleNestedName}" }
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy