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

View File

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

View File

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