How to live better without Dependency Injection

submited by
Style Pass
2021-06-09 01:30:05

(I've just learned Dagger, what is wrong? Imagine my anxiety now, I am NOT happy seeing an article with this title! I hope that the author does not have any idea!)

Five years have passed since my first Dagger 2 article. It is time to write the last one. We do not need Dagger anymore. In fact, we didn't even need it in the first place.

Dagger allows us to solve many issues that we have with OOP code. It helps with testing, makes code declarative, makes it easy to use some best programming practices, verifies the dependency graph at compile-time, and allows us to look down on the developers who are not able to understand it.

It increases build time and, like any other code generator, it causes build configuration issues. Some developers have to clean their projects before building even though they have changed just one line. Incremental compilation breaks often. I heard of a project where Dagger takes 50% of the build time. Maybe it is OK for some, but I waste more than 10 hours monthly waiting for my builds, adding another 10 hours would not help.

Build configs, configuration classes, configuration interfaces, annotations, scopes, modules, components, whatever. This is ridiculously complex for a developer who just wants to get a dependency. If we want to use Dagger for tests it comes with an even bigger tax.

Leave a Comment