3 ms·
I don't really use dependency injection. I once had tried to penetrate a Java program that used dependency injection using Guice to initialise a bunch of things
by commandersaki 4y ago
I don't really use dependency injection. I once had tried to penetrate a Java program that used dependency injection using Guice to initialise a bunch of things/dependencies, and I found it abstracted away the control flow that I really couldn't figure out how to modify things at initialization time. I eventually abandoned the pursuit because I was out of time and had to work on other things.
But looking at this example, I don't really see the benefit in the example. You save 2 lines of code, but now you have all these additional build steps you need to maintain? I'm trying to honestly see the value of dependency injection; admittedly in Go it's a lot easier to follow and understand these frameworks compared to Java, but I'm not really understanding how it's saving time or helping me. The other issue is I have to understand the concept of dependency injection and while simple at its core, a quick google gives you examples and tutorials in the most complicated framework.
I really dislike these abstractions that hijack the flow of initialising your program; I'd rather just do everything manually. Maybe I've not met a codebase where I need to manage say 100 dependencies, but even then, I'd probably just prefer straight-line obvious code on individually setting them up and initialising the program.
Edit: I realise I actually like manual DI, I just despise the frameworks and found them more irritating than useful. Dependency injection has never been an easy topic for me to understand.
- za3faran 4y ago> admittedly in Go it's a lot easier to follow and understand these frameworks compared to Java That's because the golang ones are doing lesser work. There's nothing inherent in Java that makes such frameworks in it more difficult to follow. As a matter of fact, it could be the opposite with the presence of mature IDEs that allow you to navigate to the injection point and see the relevant graph. I recall working on a golang project that did not use DI, and it was a total mess to read and write.