Last active
December 6, 2021 17:47
-
-
Save WendyYanto/8eef5c28a6f36d765ef59a80e685fac2 to your computer and use it in GitHub Desktop.
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
object Injector { | |
fun <T : InjectorModule, R : Any> inject(kClass: KClass<T>, entryPointClass: R) { | |
// get all provider methods | |
val methods = kClass.java.declaredMethods | |
.filter { method -> method.isAnnotationPresent(Provides::class.java) } | |
// construct module instance | |
val moduleInstance = kClass.java.newInstance() | |
// construct and cache dependencies | |
val dependencies: MutableMap<Class<*>, Any> = mutableMapOf() | |
methods.forEach { method -> | |
dependencies[method.returnType] = method.invoke(moduleInstance) | |
} | |
// ToDo: inject dependencies | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment