top | item 34303545

(no title)

erpellan | 3 years ago

Never ceases to amaze me how much passion calling a constructor can evoke.

I have never, ever, been in a situation where calling constructors was simplified by adding a DI framework.

discuss

order

9dev|3 years 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|3 years ago

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.