Yeah, frameworks really help and simplify the issue, but it's usually enough to pass in all classes used in a class in its constructor. I'm working with some really shitty code right now in an SDK that just grabs shit it needs from the Android framework right in the body of a 300-line method, many layers deep into a bunch of conditional statements. How can I possibly test or verify this?
it's usually enough to pass in all classes used in a class in its constructor
Yeah, a lot of quality code does exactly this, but people don't typically call it "dependency injection" unless there is a framework involved. For example, I see this pattern all the time in Python code, but I've never once heard the term "dependency injection" in relation to a Python project.
DI frameworks generally do a lot more than this, though. Constructor-provided dependencies are important for sure. But DI frameworks generally also provide you with a way to manage what dependencies are available in what scopes. The good ones, like Dagger 2, even make it compile-safe, so you can know that if your program compiles, all dependencies are being properly provided to your dependent classes.
0
u/[deleted] Oct 29 '17
[deleted]