From 29b56ceb4058e905bd7cd8cef16edcbdff47e0cf Mon Sep 17 00:00:00 2001 From: vsavkin Date: Tue, 22 Sep 2015 12:53:35 -0700 Subject: [PATCH] cleanup(di): make DependencyProvider private --- modules/angular2/src/core/di/injector.ts | 36 ++++++------------- .../angular2/test/core/di/injector_spec.ts | 7 ++-- modules/angular2/test/public_api_spec.ts | 4 --- 3 files changed, 14 insertions(+), 33 deletions(-) diff --git a/modules/angular2/src/core/di/injector.ts b/modules/angular2/src/core/di/injector.ts index febda3b9b6..9dbcd8a093 100644 --- a/modules/angular2/src/core/di/injector.ts +++ b/modules/angular2/src/core/di/injector.ts @@ -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, - depProvider: DependencyProvider = null): Injector { + static resolveAndCreate(bindings: Array): 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, - depProvider: DependencyProvider = null): Injector { + resolveAndCreateChild(bindings: Array): 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; } diff --git a/modules/angular2/test/core/di/injector_spec.ts b/modules/angular2/test/core/di/injector_spec.ts index 6d773229d4..f5904a2c5e 100644 --- a/modules/angular2/test/core/di/injector_spec.ts +++ b/modules/angular2/test/core/di/injector_spec.ts @@ -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")) diff --git a/modules/angular2/test/public_api_spec.ts b/modules/angular2/test/public_api_spec.ts index 77d25478d8..76b8d0d0ad 100644 --- a/modules/angular2/test/public_api_spec.ts +++ b/modules/angular2/test/public_api_spec.ts @@ -497,10 +497,6 @@ const NG_API = [ 'Key.get', 'Key.numberOfKeys', - 'KeyRegistry', - 'KeyRegistry.get', - 'KeyRegistry.numberOfKeys', - 'KeyValueDiffers', 'KeyValueDiffers.create', 'KeyValueDiffers.extend',