Is there a way to know if there are unused depende...
# kodein
d
Is there a way to know if there are unused dependencies in Kodein-DI? It's a big more difficult when everything is
instance()
and
factory()
in the bindings... it greatly reduces typing but sometimes leaves dangling dependencies...
r
It's not a total solution to your problem, but I always skip the type inference for these functions, and explicitly type them, as well as mark my modules with
@Suppress("RemoveExplicitTypeArguments")
. It's a bit more typing/maintenance, but I find the explicitness helps self-document the dependencies.
d
That's one way of doing things 🙂, but I was looking more for some kind of log that can be printed out... there's already a function that prints out the container. Or it might come in handy by hacking out a unit test that checks the function that returns unused bindings returns an empty list...
a
Printing the whole container is easy, but how do you list unused classes? Kodein gets to know at runtime which classes are used only if a particular part of your project is called (e. g.
ErrorLogger
is only used when an exception occurs).
d
I don't mean unused in the whole app... I just mean the inter-dependencies in the container. Most dependecies by me are constructor injected, so even a list of the ones not injected in the Kodein instance, could help in tracking down unused dependencies. Anyways, the ones that I use in the app are just api endpoints that are much easier to track. The other option would be to have some kind of dependency graph similar to gradle.