Hacker News new | ask | show | jobs
by 9dev 1255 days ago
Until you want to add an argument to that constructor and find yourself modifying lots of files just to update that call everywhere.

Or need a value from the application config, and have to patch the configuration instance through, several levels of classes deep. After wasting a day or two with those shenanigans, you’ll gladly take the DI framework, which makes both scenarios a single-line, 10 second change.

1 comments

Or just create two versions of the constructor - one that takes the arg, and one that doesn't.

The one that doesn't does whatever magic you were planning for the DI, does that, then calls the constructor with the arg.

Planning magic isn't necessary! What if your class requires a new dependency?