3 ms·
Smells like you're not doing DI properly :)
by reader_mode 6y ago
Smells like you're not doing DI properly :)
- scns 6y agoIs it a bad design, if it could be held wrong?
- reader_mode 6y agoWell from the sound of it he's instantiating objects manually 5 levels deep and he has control over all those constructors since he passed a new parameter through all of them. So it sounds like basically he's not using DI (is just using it to pass stuff to controllers) and is surprised that using a library designed around DI is awkward. The correct solution is use DI to construct that hierarchy and then you can just request IOptions at the bottom/where you need it.
- munchbunny 6y agoYou can hold pretty much anything wrong. Sometimes the onus is on the user to understand the tools. Sometimes the onus is on the tools to not be unnecessarily dangerous. DI is a well understood pattern, it just takes some time to wrap your head around it.