2 ms·
Well, the coupling is there whether you're using DI or a Registry, it's just a question of where the code expects its dependency to be. In DI, the dependency is
by vinceguidry 12y ago
Well, the coupling is there whether you're using DI or a Registry, it's just a question of where the code expects its dependency to be. In DI, the dependency is passed in as part of the sets of arguments, in a Registry, it expects it to be somewhere else.
What I like about using a class object to hold the state is that the class is being depended on anyway, so you're not introducing any 'extra' coupling. I also like to allow the dependency to be passed in as an argument, with the default being to grab it out the registry, for testing purposes or in case I'm hooking into the code with a REPL for whatever reason. This way you get the benefits of DI without littering your classes with keyword arguments that, 99% of the time are only going to interact with one thing.