Get Kodein dependencies by type
1 min readJan 2, 2020
Sometimes it can be very useful to get from your DI container all the dependencies of a certain type or sub-type.
In this brief example I illustrate how you can request all instances by interface (Animal), sub-interface (Cat), or class (Dog). This works with both kodein-di-generic-jvm
and kodein-di-erased-jvm.
The output is:
Greet the cats:
Hello! I'm a persian cat
Hello! I'm a ginger catGreet the dog:
Hello! I'm a dogGreet all the animals:
Hello! I'm a persian cat
Hello! I'm a ginger cat
Hello! I'm a dog