Is there a dependency dependency in Rails?

Does the fact that Rails has an MVC approach mean there is dependency injection?

Or is there a reason we are not talking about dependency injection in Rails?

If Rails has dependency injection, what is it?

+46
spring ruby dependency-injection ruby-on-rails
03 Feb '10 at 9:15
source share
5 answers

Injection injection is usually not needed by Ruby. Jamis Buck spoke in detail about the reasons. Well worth a read.

+8
Feb 03 '10 at 9:25 am
source share

IoC is a big hammer, but DI happens every day in Ruby / Rails. Whenever you do:

def initialize(model_klass) @model_klass = model_klass end 

This is DI. This paradigm is also used in various places in the Rails source code. For example, the Railties stone Railties is basically a DI engine. You can enter your preferred ORM, various plugin configurations and generators.

Injection Dependency has a big and scary name, but what it minimizes is simply to untie class dependencies by injecting dependencies at run time.

It doesn't matter what language you use, if you need to connect behavior / code somewhere, you are probably using it.

+10
Feb 19 '13 at 19:36
source share

Dependency injection is a paradigm, so it exists in every object-oriented language.

Is there any DI framework for Ruby - check this question

+8
Feb 03 '10 at 9:25 am
source share

I would say that you don’t need such a thing with ruby ​​... but if you really want it, some people have workarounds .

0
Feb 03 '10 at 9:26 a.m.
source share

I use this IoC https://github.com/alexeypetrushin/micon in my web structure, most of the time it remains hidden and silently resolves dependency problems and component initialization, which otherwise would have to be resolved manually.

You can see it in action here http://ruby-lang.info (this site works with Rad, my web framework is https://github.com/alexeypetrushin/rad_core ).

0
Jun 17 '11 at 18:47
source share