Vojta Jina - Dependency Injection - NG-Conf
Why Stack Overflow recommends it
Stack Overflow users link it when answering questions about dependency injection in Angular and Node.js, since it explains the ideas behind Angular's injector from one of its designers.
Recommended by 2 people across 2 different months, 2014 to 2017.
What it is
A 25-minute conference talk from ng-conf 2014 in which Vojta Jina, a member of the Angular team, explains how dependency injection works and how it was being redesigned for the future of Angular. It covers the wiring side of DI and why a good injector matters for testability and modularity.
What people said
Recommends analog-nico · 2014-07 · Stack Overflow · on “Node.js, Express and Dependency Injection”
You have some good thoughts to which I'd like to add: Having stateless modules will help you to scale your app horizontally. If all state is in a database it will be easy to run multiple node.js instances in parallel. I also prefer to inject everything. Otherwise the time will come when I would like to write a unit test and it gets hard because I have a hardcoded (not injected) dependencies I can't mock. To keep this lightweight feeling when working with node you need an approach for dependency injection that doesn't add too much complexity. Your express example above reminds me of a talk by Vojta Jina [this video] in which he makes an important point about the wiring part of dependency injection
Recommends Billy Blaze · 2015-02 · Stack Overflow · on “Login using angularjs?”
just replace ``$get: ['DI', function ($DI) {`` with ``$get: ['$http', '$q', function ($http, $q) {``. Also if your new I would suggest to watch a few lenghty youtube presentations (like [this video] )
Cites analog-nico · 2014-04 · Stack Overflow · on “Using a global variable in Node.js for dependency injection”
Your approach is a clear and simple one which is good. Whether you have a global variable or require your module every time is not important. Regarding testability it allows you to replace your modules with mocks. For unit testing you should add a function that makes it easy for you to apply different mocks for each test. Something that extends your dependency map temporarily. For further reading I can recommend a great blog article on dependency injection in Node.js [LINK] as well as a talk on the future dependency injector of angular.js [this video] which is designed by some serious masterminds. BTW, you might be interested in Fire Up! [LINK] which is a dependency injection container I implemen
Cites Mr. Baudin · 2014-09 · Stack Overflow · on “Use RequireJS to lazy load AngularJS DI components”
At the moment it is not possible to change the implementation. AngularJS does not have a set way to change the ServiceProvider to return custom promisses instead of concrete objects. This will be possible in the future of AngularJS as Vojta Jina [LINK] explains in this Youtube video [this video] .
Cites Paul Sweatte · 2015-07 · Stack Overflow · on “What is the type friendly injection?”
In AngularJS, you can inject dependencies in multiple ways: in the directive link function by position in the directive definition by name in the controller function by name in the factory function by name in the service function by type Type friendly injection allows you to implicity invoke a constructor function by reference: myApp.service('Pattern', ["Infinity", RegExp]); rather than by explicity using the new keyword: myApp.factory('Pattern', ["Infinity", function(Infinity) { return new RegExp(Infinity); } ]); OR function goInfinity(Infinity) { return new RegExp(Infinity); } goInfinity.$inject = ["Infinity"]; myApp.factory('Pattern', goInfinity); The Service recipe produces a service jus
Cites looooongname · 2017-11 · Stack Overflow · on “When to use ng2 Injector.resolveAndCreate vs TypeScript constructor”
I read this article [LINK] and watched these videos about Dependency Injection in Angular 2: Vojta Jina - Dependency Injection - NG-Conf [this video] Dependency Injection in Angular 2 by Pascal Precht [LINK] and quite understand about DI in Angular. But I'm confused on how to use it right. My question is when to use Type Definition(1) like this: import { Component } from '@angular/core'; import { Http } from '@angular/http'; @Component({ selector: 'example-component', template: '<div>I am a component</div>' }) class ExampleComponent { constructor(private http: Http) {} } And when to use Injector (2) like this: import { Injector, provide } from 'angular2/core' var injector = Injector.resolveAndCre