All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.assembly.RaptorServiceComponent.kt Maven / Gradle / Ivy

There is a newer version: 0.27.0
Show newest version
package io.fluidsonic.raptor.lifecycle

import io.fluidsonic.raptor.*
import io.fluidsonic.raptor.di.*
import kotlin.reflect.*


public class RaptorServiceComponent internal constructor(
	private val factory: RaptorDI.() -> Service,
	private val name: String,
) : RaptorComponent.Base>(RaptorLifecyclePlugin) {

	private val diKey = ServiceDIKey(name)
	private val providedKeys: MutableList> = mutableListOf()


	@RaptorDsl
	public fun provides(key: RaptorDIKey): RaptorServiceComponent =
		apply {
			providedKeys += key
		}


	// https://youtrack.jetbrains.com/issue/KT-209/Add-lower-bounds-for-generic-type-parameters-at-first-consider-it
	@RaptorDsl
	public inline fun > provides(@Suppress("UNUSED_PARAMETER") type: Type): RaptorServiceComponent =
		provides(RaptorDIKey(checkNotNull(typeOf().arguments.single().type)))


	internal fun registration(): RaptorServiceRegistration =
		RaptorServiceRegistration(
			factory = factory,
			name = name,
			providedKeys = providedKeys.toList(),
		)


	override fun toString(): String = "service '$name'"
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy