Move Bob around.
This commit is contained in:
parent
903d1973c2
commit
b07bfd45d3
5 changed files with 5 additions and 5 deletions
|
|
@ -5,7 +5,7 @@ import androidx.compose.runtime.mutableStateOf
|
|||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.graphics.painter.BitmapPainter
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import com.pixelized.biblib.injection.get
|
||||
import com.pixelized.biblib.utils.injection.get
|
||||
import com.pixelized.biblib.utils.BitmapCache
|
||||
import java.net.URL
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package com.pixelized.biblib.utils.injection
|
||||
|
||||
import com.pixelized.biblib.utils.exception.InjectionException
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
object Bob {
|
||||
private val components = hashMapOf<KClass<*>, Any>()
|
||||
|
||||
operator fun <I : Any, O : I> set(clazz: KClass<I>, component: O) {
|
||||
components[clazz] = component
|
||||
}
|
||||
|
||||
operator fun <T> get(clazz: KClass<*>): T {
|
||||
return components[clazz] as? T ?: throw InjectionException(clazz)
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T> get(): T = Bob[T::class]
|
||||
|
||||
inline fun <reified T> inject(): Lazy<T> = lazy { Bob[T::class] }
|
||||
Loading…
Add table
Add a link
Reference in a new issue