refactor(di): make use of optional parameters

This commit is contained in:
vsavkin 2014-10-10 09:56:43 -04:00
parent 3f3fb7017e
commit 97667e2591
3 changed files with 6 additions and 8 deletions

View File

@ -50,7 +50,7 @@ export class BindingBuilder {
);
}
toFactory(factoryFunction:Function, {dependencies=null}={}):Binding {
toFactory(factoryFunction:Function, dependencies:List = null):Binding {
return new Binding(
Key.get(this.token),
reflector.convertToFactory(factoryFunction),
@ -59,7 +59,7 @@ export class BindingBuilder {
);
}
toAsyncFactory(factoryFunction:Function, {dependencies=null}={}):Binding {
toAsyncFactory(factoryFunction:Function, dependencies:List = null):Binding {
return new Binding(
Key.get(this.token),
reflector.convertToFactory(factoryFunction),

View File

@ -19,11 +19,11 @@ function _isWaiting(obj):bool {
export class Injector {
constructor(bindings:List) {
constructor(bindings:List, parent:Injector = null) {
var flatten = _flattenBindings(bindings, MapWrapper.create());
this._bindings = this._createListOfBindings(flatten);
this._instances = this._createInstances();
this._parent = null; //TODO: vsavkin make a parameter
this._parent = parent;
this._asyncStrategy = new _AsyncInjectorStrategy(this);
this._syncStrategy = new _SyncInjectorStrategy(this);
@ -46,9 +46,7 @@ export class Injector {
}
createChild(bindings:List):Injector {
var inj = new Injector(bindings);
inj._parent = this; //TODO: vsavkin: change it when optional parameters are working
return inj;
return new Injector(bindings, this);
}

View File

@ -125,7 +125,7 @@ export function main() {
it('should support overriding factory dependencies', function () {
var injector = new Injector([
Engine,
bind(Car).toFactory((e) => new SportsCar(e), {dependencies: [Engine]})
bind(Car).toFactory((e) => new SportsCar(e), [Engine])
]);
var car = injector.get(Car);