Skip to content

Instantly share code, notes, and snippets.

@WendyYanto
Last active December 6, 2021 17:47
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 WendyYanto/8eef5c28a6f36d765ef59a80e685fac2 to your computer and use it in GitHub Desktop.
Save WendyYanto/8eef5c28a6f36d765ef59a80e685fac2 to your computer and use it in GitHub Desktop.
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