cleanup(di): make DependencyProvider private

This commit is contained in:
vsavkin 2015-09-22 12:53:35 -07:00 committed by Victor Savkin
parent 820b30c181
commit 29b56ceb40
3 changed files with 14 additions and 33 deletions

View File

@ -387,6 +387,7 @@ export class BindingWithVisibility {
}
/**
* @private
* Used to provide dependencies that cannot be easily expressed as bindings.
*/
export interface DependencyProvider {
@ -469,9 +470,6 @@ export class Injector {
* The passed-in bindings can be an array of `Type`, {@link Binding},
* or a recursive array of more bindings.
*
* The method also takes an optional {@link DependencyProvider}, which is used to
* resolve dependencies that cannot be expressed as bindings.
*
* ### Example ([live demo](http://plnkr.co/edit/ePOccA?p=preview))
*
* ```typescript
@ -492,10 +490,9 @@ export class Injector {
* because it needs to resolve the passed-in bindings first.
* See {@link resolve} and {@link fromResolvedBindings}.
*/
static resolveAndCreate(bindings: Array<Type | Binding | any[]>,
depProvider: DependencyProvider = null): Injector {
static resolveAndCreate(bindings: Array<Type | Binding | any[]>): Injector {
var resolvedBindings = Injector.resolve(bindings);
return Injector.fromResolvedBindings(resolvedBindings, depProvider);
return Injector.fromResolvedBindings(resolvedBindings);
}
/**
@ -503,9 +500,6 @@ export class Injector {
*
* This API is the recommended way to construct injectors in performance-sensitive parts.
*
* The method also takes an optional {@link DependencyProvider}, which is used to
* resolve dependencies that cannot be expressed as bindings.
*
* ### Example ([live demo](http://plnkr.co/edit/KrSMci?p=preview))
*
* ```typescript
@ -523,12 +517,10 @@ export class Injector {
* expect(injector.get(Car) instanceof Car).toBe(true);
* ```
*/
static fromResolvedBindings(bindings: ResolvedBinding[],
depProvider: DependencyProvider = null): Injector {
static fromResolvedBindings(bindings: ResolvedBinding[]): Injector {
var bd = bindings.map(b => new BindingWithVisibility(b, Visibility.Public));
var proto = new ProtoInjector(bd);
var inj = new Injector(proto, null, depProvider);
return inj;
return new Injector(proto, null, null);
}
_strategy: InjectorStrategy;
@ -539,7 +531,7 @@ export class Injector {
* Private
*/
constructor(public _proto: any /* ProtoInjector */, public _parent: Injector = null,
private _depProvider: DependencyProvider = null,
private _depProvider: any /* DependencyProvider */ = null,
private _debugContext: Function = null) {
this._strategy = _proto._strategy.createInjectorStrategy(this);
}
@ -636,9 +628,6 @@ export class Injector {
* The passed-in bindings can be an array of `Type`, {@link Binding},
* or a recursive array of more bindings.
*
* The methods also takes an optional {@link DependencyProvider}, which is used to
* resolved dependencies that cannot be expressed as bindings.
*
* ### Example ([live demo](http://plnkr.co/edit/opB3T4?p=preview))
*
* ```typescript
@ -657,10 +646,9 @@ export class Injector {
* because it needs to resolve the passed-in bindings first.
* See {@link resolve} and {@link createChildFromResolved}.
*/
resolveAndCreateChild(bindings: Array<Type | Binding | any[]>,
depProvider: DependencyProvider = null): Injector {
resolveAndCreateChild(bindings: Array<Type | Binding | any[]>): Injector {
var resolvedBindings = Injector.resolve(bindings);
return this.createChildFromResolved(resolvedBindings, depProvider);
return this.createChildFromResolved(resolvedBindings);
}
/**
@ -671,9 +659,6 @@ export class Injector {
*
* This API is the recommended way to construct injectors in performance-sensitive parts.
*
* The methods also takes an optional {@link DependencyProvider}, which is used to
* resolved dependencies that cannot be expressed as bindings.
*
* ### Example ([live demo](http://plnkr.co/edit/VhyfjN?p=preview))
*
* ```typescript
@ -691,11 +676,10 @@ export class Injector {
* expect(child.get(ParentBinding)).toBe(parent.get(ParentBinding));
* ```
*/
createChildFromResolved(bindings: ResolvedBinding[],
depProvider: DependencyProvider = null): Injector {
createChildFromResolved(bindings: ResolvedBinding[]): Injector {
var bd = bindings.map(b => new BindingWithVisibility(b, Visibility.Public));
var proto = new ProtoInjector(bd);
var inj = new Injector(proto, null, depProvider);
var inj = new Injector(proto, null, null);
inj._parent = this;
return inj;
}

View File

@ -109,8 +109,8 @@ export function main() {
bindings: dynamicBindings,
strategyClass: InjectorDynamicStrategy
}].forEach((context) => {
function createInjector(bindings: any[], dependencyProvider = null) {
return Injector.resolveAndCreate(bindings.concat(context['bindings']), dependencyProvider);
function createInjector(bindings: any[]) {
return Injector.resolveAndCreate(bindings.concat(context['bindings']));
}
describe(`injector ${context['strategy']}`, () => {
@ -367,7 +367,8 @@ export function main() {
depProvider.spy("getDependency").andReturn(e);
var bindings = Injector.resolve([Car]);
var injector = Injector.fromResolvedBindings(bindings, depProvider);
var proto = new ProtoInjector([new BindingWithVisibility(bindings[0], Visibility.Public)]);
var injector = new Injector(proto, null, depProvider);
expect(injector.get(Car).engine).toEqual(e);
expect(depProvider.spy("getDependency"))

View File

@ -497,10 +497,6 @@ const NG_API = [
'Key.get',
'Key.numberOfKeys',
'KeyRegistry',
'KeyRegistry.get',
'KeyRegistry.numberOfKeys',
'KeyValueDiffers',
'KeyValueDiffers.create',
'KeyValueDiffers.extend',