feat(di): add support for optional dependencies

This commit is contained in:
vsavkin
2015-02-27 07:42:51 -08:00
committed by Misko Hevery
parent 23786aaa92
commit ba0a1ec459
7 changed files with 102 additions and 31 deletions
+17 -1
View File
@@ -1,5 +1,5 @@
import {describe, ddescribe, it, iit, expect, beforeEach} from 'angular2/test_lib';
import {Injector, Inject, InjectLazy, bind} from 'angular2/di';
import {Injector, Inject, InjectLazy, Optional, bind} from 'angular2/di';
class Engine {
}
@@ -34,6 +34,13 @@ class CarWithLazyEngine {
}
}
class CarWithOptionalEngine {
engine;
constructor(@Optional() engine:Engine) {
this.engine = engine;
}
}
class CarWithDashboard {
engine:Engine;
dashboard:Dashboard;
@@ -159,6 +166,15 @@ export function main() {
expect(car.engine).toBeAnInstanceOf(Engine);
});
it('should support optional dependencies', function () {
var injector = new Injector([
CarWithOptionalEngine
]);
var car = injector.get(CarWithOptionalEngine);
expect(car.engine).toEqual(null);
});
it("should flatten passed-in bindings", function () {
var injector = new Injector([
[[Engine, Car]]