DEV Community

Discussion on: Episode 005 - Dependency Injection - ASP.NET Core: From 0 to overkill

 
chenge profile image
chenge
class PlayController < Controller

  def create(params)
     store = Invoice
     Invoice.generate_invoice(params, store)
     ... 
  end
end


In Ruby code is like this. Don't need a DI container.

Thread Thread
 
joaofbantunes profile image
João Antunes

Yupe. Different ways to get to the same end result of decoupling components 🙂

I like the C# approach, probably because I'm used to it, but I can understand that coming from other languages it seems overly complex.

Being able to just declare the dependencies in the constructor and they'll be there when running is nice (even if a bit magic) and gives quick visibility on the dependencies of a given class just by looking at the constructor. It does come with the hidden complexity you talked about, so as always, there are trade offs.