import kotlin.reflect.KClass interface Singleton abstract class UIComponent abstract class View : Singleton, UIComponent() abstract class Fragment : UIComponent() val injectionContext = mutableMapOf, Singleton>() fun findSingleton(type: KClass): T { if (!injectionContext.containsKey(type)) injectionContext[type] = type.java.newInstance() return injectionContext[type] as T } fun findFragment(type: KClass): T = type.java.newInstance() inline fun findUIComponent(type: KClass): T? { if (T::class is View) { return findSingleton(type) } if (T::class is Fragment) { return findFragment(type) } return null }