Created
October 15, 2019 10:40
-
-
Save DominicFinn/1c945e89878e3142967dacc0050f2344 to your computer and use it in GitHub Desktop.
KotlinIoC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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