2 ms·
There is a good reason to force people to use dependency injection. At least you're sure that their code will use an interface to describe a dependency which is
by _throwmaybe_ 12y ago
There is a good reason to force people to use dependency injection.
At least you're sure that their code will use an interface to describe a dependency which is a huge advantage compared to letting everybody write their own code as they want.
- kaens 12y agoThe issue with this, in my experience, is that if you don't understand the driving principles behind DI patterns (prefer to depend on an interface or set of behaviors, prefer to be given something that satisfies that dependency instead of instantiating it yourself, with the aim of not doing things you aren't responsible for), you can end up with what amounts to either rather messy global state, or with systems that are still very highly coupled but have good paint. I can't help but see discussions about DI as suffering from sounding fancier than it is and also from less-experienced devs thinking that they must be writing "correct" code because it has the general shape of the DI pattern they read about. If it were my choice, I'd ditch the terminology and best practices all together in favor of active practice critically thinking about the dependencies, responsibilities, and assumptions of code being written or read.