I’m studying dependency injection and I want to know if required function parameters can be considered dependencies.
I’d just like to make sure before I go around referring to them dependencies and that turns out to not be exactly accurate.
function doSomething(required){
if(required !== null){
// do stuff
}
}
Are the required parameters of a function called dependencies?
Not necessarily.
If you look at the Wikipedia Article, you’ll find that a Dependency is considered a service. In practical terms, this is going to be an object of some sort (a reference type to be more exact). While that object is going to be passed to some class constructor as a parameter, not all constructor parameters are service objects, and therefore not all parameters are dependencies in that sense.
Most IoC Containers are tasked with creating objects, not satisfying primitive (value type) constructor parameters.