1

We just picked up Aurelia. First off, it's great. I love using it so far. It seems to be very modular, which I like. But I got to thinking about WHY they use DI. What's the advantage of using DI? I know it seems to make singleton use easier, but is there any other reason?

From what I understand (and I could be wrong), instead of doing this:

myObj = new myObj();

you do this:

@autoInject
export class myClass {
     constructor(myObj) {
          this.variable = myObj;
     }
}

So, I can't really seem to find an advantage to why people use DI in general. Are there any other reasons that I don't know about?

Brandon
  • 3,074
  • 3
  • 27
  • 44
  • Also see http://programmers.stackexchange.com/questions/19203/what-are-the-benefits-of-using-dependency-injection-and-ioc-containers . The question falls into 'too broad' category in its current state and there's no good answer for it. The reasons are 'architectural benefits', this doesn't explain a lot, does it? This doesn't apply to Aurelia in particular but to any other framework that does DI/IoC. – Estus Flask Jul 06 '16 at 21:34

1 Answers1

0

As stated in the comments, this is a really broad question. But there are some good answers provided by Jeremy Danyow:

https://www.danyow.net/inversion-of-control-with-aurelia-part-1/ https://www.danyow.net/inversion-of-control-with-aurelia-part-2/

At a high level, Aurelia embraces the IoC paradigm -- inversion of control -- where DI is the mechanism of inverting the control. IoC is a pattern where a framework or library controls custom code, rather than custom code using a framework or library. Read the articles for more. Hope that helps.

Todd Price
  • 2,650
  • 1
  • 18
  • 26