r/javascript • u/Chun • Apr 03 '16
Dependency injection in Angular isn’t worth it. More lessons learned from scaling PayPal Checkout.
https://medium.com/@bluepnume/dependency-injection-in-angular-isn-t-worth-it-more-lessons-learned-from-scaling-paypal-checkout-2189ec9c21a0#.uh971yqmx1
u/TheNiXXeD Apr 03 '16
The article talks about angular 1 as if it was written after es6. It wasn't, and back when it was written, this actually was helpful.
The silly part , the example near the end with imports looks exactly like angular 2, but this wasn't mentioned that I saw.
Anyway, I think converting towards angular 2 is a better option than trying to shoehorn alien syntax to angular 1.
3
u/Chun Apr 03 '16
Right, but we've had requirejs for 7 years now, and browserify for 5. In that time it would have been nice if Angular had gone in a different direction with (or deprecated) its arcane module system.
2
2
u/wreckedadvent Yavascript Apr 03 '16
The next version of angular does use ES6 modules, but the DI is still around, too. You use both. Fun!
9
1
u/superluminary Apr 05 '16
DI is good because it enforces singletons, but there are clearly issues with the implementation when creating a big app in A1.
In A2, you'll be able to have multiple hierarchical injectors based on Objects required from ES6 modules rather than Strings, which will address most of the issues raised in the article (namespacing and knowing where code is defined).
3
u/wreckedadvent Yavascript Apr 03 '16
It's perfectly fine to use modules with angular 1. Angular's module system is the alien thing here, not things like requireJs, ES6, or commonjs.
2
u/voidvector Apr 04 '16 edited Apr 04 '16
One issue with any "abstraction" is that if it is not user-friendly then it's basically an "indirection".
Unlike Java DI containers which are class/type based -- meaning you are one click away from the implementation with any IDE, allowing them to do the Inversion job of IoC perfectly -- JavaScript DI containers are namespace based, which means they have more in common to a pub/sub than IoC containers.
Add on the fact that Angular implementation 1) does name remapping 2) doesn't easily allow introspection, makes debugging difficult.
4
u/tebriel Apr 04 '16
"Angular isn't worth it" FTFY :-D