Skip to content

Instantly share code, notes, and snippets.

@OliverJAsh
Created November 12, 2014 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OliverJAsh/f77efca56cdf1bb1676d to your computer and use it in GitHub Desktop.
Save OliverJAsh/f77efca56cdf1bb1676d to your computer and use it in GitHub Desktop.
DI: Car -> Engine
/* jshint esnext: true */
import * as di from 'di/src';
class Car {
constructor(engine) {
console.log('Car constructor engine: %s', engine);
}
}
// TODO: Fix ES6 class annotations
// As per: https://github.com/angular/di.js/issues/80
di.annotate(Car, new di.Inject('Engine'));
var injector = new di.Injector();
di.annotate(run, new di.InjectLazy(Car));
function run(createCar) {
createCar('Engine', 'some-engine')
}
injector.get(run);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment