Comment by almostgotcaught

Comment by almostgotcaught 3 hours ago

1 reply

> inject logical parameters to a segment of code is to use function parameters. You can have a complicated DI framework that involves Java class annotations and megabytes of XML, but that’s not the central idea.

so the central idea of dependency injection, a concept with a wiki of like 5000 words [1], is just pass parameters to functions...?

i guess i'm happy to accept that (i personally DGAF about DI or whatever) but it certainly means that all the people discussing DI (like yourself) are peddling snake oil...?

[1] https://en.wikipedia.org/wiki/Dependency_injection

philwelch 2 hours ago

> so the central idea of dependency injection, a concept with a wiki of like 5000 words [1], is just pass parameters to functions...?

Specifically, parameters that refer to a dependency that is being injected.

And yeah, there are a lot of fundamentally simple ideas that can be massively overcomplicated. Let’s take a look at that Wikipedia article:

> There are several ways in which a client can receive injected services:[29]

> * Constructor injection, where dependencies are provided through a client's class constructor.

> * Method Injection, where dependencies are provided to a method only when required for specific functionality.

> * Setter injection, where the client exposes a setter method which accepts the dependency.

> * Interface injection, where the dependency's interface provides an injector method that will inject the dependency into any client passed to it.

You’ll notice that these are more or less an enumeration of ways to pass parameters into functions in object oriented programming. Most of the complexity isn’t the idea of dependency injection itself but rather in building abstractions for doing dependency injection, especially in an object-oriented language.

And yeah, a lot of the complicated versions of DI, like Spring, probably are mostly snake oil. But I object to the notion that I am peddling snake oil because I’m not advocating for anything like Spring or claiming that DI is anything more than parameterization.