3 ms·
Passing a dependency or lambda as a function argument is dependency injection. What is different is the implementation. There's lots of dependency injection in
by tiew9Vii 3y ago
Passing a dependency or lambda as a function argument is dependency injection. What is different is the implementation. There's lots of dependency injection in pure functional programs it just doesn't look like how a typical Java project does it.
I've grown to dislike Spring DI, Google's Guice and friends. You can use basic constructor injection and wire it up in your main method with zero dependencies or framework and it ends up simpler, easier to reason about. Java has also had Lambda's for a long time now so sometimes all you need to do is pass in a Lambda.
- eddd-ddde 3y agoThe other day I had to make a change to a java file for my first time in my life in my work. I only needed to set a boolean to true in a builder. I had to: 1. Create a new annotation in some random file 2. Import said annotation in another file 3. Use a dependency injection decorator on a constructor parameter with my new annotation 4. Require said parameter via another decorator in a class method 5. Finally use the value inside the method This is even a simplification. Just why...