Skip to content

Instantly share code, notes, and snippets.

@DominicFinn
Created October 15, 2019 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominicFinn/1c945e89878e3142967dacc0050f2344 to your computer and use it in GitHub Desktop.
Save DominicFinn/1c945e89878e3142967dacc0050f2344 to your computer and use it in GitHub Desktop.
KotlinIoC
package sample
import kotlin.reflect.KClass
interface ICat {
}
class Felix : ICat
{
}
interface ICatHouse
{
}
class CatHouse(private val cat: ICat) : ICatHouse
{
}
class MiniIoC
{
companion object {
val types = HashMap<KClass<*>, KClass<*>>()
}
fun Bind(i :KClass<*>, c: KClass<*>) {
if (!types.containsKey(i))
types[i] = c;
throw Exception("Bang")
}
private fun <T> internalResolve(value : T) {
}
fun <T> Resolve(): T {
// get the type of T....
// look up T in the Hashmap which returns the KClass value
// work out how to instantiate the KClass value... hint, it might also have dependencies....
// return the instance.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment