3 ms·
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 a
by 9dev 4y 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.
- ars 4y agoOr 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.
- 9dev 4y agoPlanning magic isn't necessary! What if your class requires a new dependency?