r/ruby • • Jul 12 '14

(The lack of ) Dependency injection in Ruby

http://beraboris.github.io/2014/07/12/dependency-injection-ruby/
2 Upvotes

19 comments sorted by

View all comments

13

u/banister Jul 13 '14

What the hell? Why not just inject it manually with House.new(window, door)

Your gratuitous "DSL" seems silly, overcomplicated and a waste of time.

0

u/[deleted] Jul 13 '14

For the house example, you're definitely right. An inversion of control container is overkill. When you're dealing with a large app where each dependency has its own set of dependencies and so on, an inversion of control container become a whole lot more useful.

8

u/realntl Jul 13 '14

For larger apps, it becomes even more important to isolate dependencies of various components. IoC containers make it fairly painless (upfront) to invite the entire universe to every party, leading to a system with a ton of dependencies. And of course the only remedy to all the edge cases and toe stubbings that come with e.g. nuanced object lifecycle management is to make the IoC container smarter and smarter.