commonMain.com.makeevrserg.mobile.di_container.Module.kt Maven / Gradle / Ivy
package com.makeevrserg.mobile.di_container
import kotlin.reflect.KProperty
/**
* [Module] could be used to create Singletons with only one initialization
* If you want to use singleton which could be reloadable see [IReloadable]
*/
abstract class Module : Dependency {
protected abstract fun initializer(): T
private val lazyValue by lazy {
initializer()
}
override val value: T
get() = lazyValue
}
fun module(initializer: () -> T) = object : Module() {
override fun initializer(): T = initializer()
}
inline operator fun Module.getValue(t: K?, property: KProperty<*>): T = value
© 2015 - 2025 Weber Informatics LLC | Privacy Policy