For all the DI examples I've seen, I always see dependencies like other classes, such as services. But an object can depend heavily, mainly and / or to a decisive extent, on configuration values such as strings and resource wrappers (file / path / URL URI / URL, rather than an entire line or document of great importance) or <reader> .
Please note: this is a DI design pattern only in Java or C # syntax, not how any specific DI environment does it.
For example, suppose I have this class that returns String (a relative path based on some obscure implementation logic). It (rather, its various developers) has a configuration / initialization dependency on "projectLocation", since the user can have different projects on his machine, and this class will execute some logic based on this project whenever it is called.
public abstract class PathResolver { protected File projectFilesLocation; public RoutinePathResolver(File projectFilesLocation) { this.projectFilesLocation = projectFilesLocation; } public abstract String getPath(String someValue); }
I don’t use DI only for unit testing (suffocating, I don’t even test unit, existing project). I just want to separate my addiction / creation problems and logical moments.
Zombies
source share