refactor(di): make use of optional parameters
This commit is contained in:
parent
3f3fb7017e
commit
97667e2591
|
@ -50,7 +50,7 @@ export class BindingBuilder {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
toFactory(factoryFunction:Function, {dependencies=null}={}):Binding {
|
toFactory(factoryFunction:Function, dependencies:List = null):Binding {
|
||||||
return new Binding(
|
return new Binding(
|
||||||
Key.get(this.token),
|
Key.get(this.token),
|
||||||
reflector.convertToFactory(factoryFunction),
|
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(
|
return new Binding(
|
||||||
Key.get(this.token),
|
Key.get(this.token),
|
||||||
reflector.convertToFactory(factoryFunction),
|
reflector.convertToFactory(factoryFunction),
|
||||||
|
|
|
@ -19,11 +19,11 @@ function _isWaiting(obj):bool {
|
||||||
|
|
||||||
|
|
||||||
export class Injector {
|
export class Injector {
|
||||||
constructor(bindings:List) {
|
constructor(bindings:List, parent:Injector = null) {
|
||||||
var flatten = _flattenBindings(bindings, MapWrapper.create());
|
var flatten = _flattenBindings(bindings, MapWrapper.create());
|
||||||
this._bindings = this._createListOfBindings(flatten);
|
this._bindings = this._createListOfBindings(flatten);
|
||||||
this._instances = this._createInstances();
|
this._instances = this._createInstances();
|
||||||
this._parent = null; //TODO: vsavkin make a parameter
|
this._parent = parent;
|
||||||
|
|
||||||
this._asyncStrategy = new _AsyncInjectorStrategy(this);
|
this._asyncStrategy = new _AsyncInjectorStrategy(this);
|
||||||
this._syncStrategy = new _SyncInjectorStrategy(this);
|
this._syncStrategy = new _SyncInjectorStrategy(this);
|
||||||
|
@ -46,9 +46,7 @@ export class Injector {
|
||||||
}
|
}
|
||||||
|
|
||||||
createChild(bindings:List):Injector {
|
createChild(bindings:List):Injector {
|
||||||
var inj = new Injector(bindings);
|
return new Injector(bindings, this);
|
||||||
inj._parent = this; //TODO: vsavkin: change it when optional parameters are working
|
|
||||||
return inj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -125,7 +125,7 @@ export function main() {
|
||||||
it('should support overriding factory dependencies', function () {
|
it('should support overriding factory dependencies', function () {
|
||||||
var injector = new Injector([
|
var injector = new Injector([
|
||||||
Engine,
|
Engine,
|
||||||
bind(Car).toFactory((e) => new SportsCar(e), {dependencies: [Engine]})
|
bind(Car).toFactory((e) => new SportsCar(e), [Engine])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var car = injector.get(Car);
|
var car = injector.get(Car);
|
||||||
|
|
Loading…
Reference in New Issue