feat(di): change the params of Provider and provide to start with "use"
Closes #4684
This commit is contained in:
@@ -49,17 +49,17 @@ export function applicationDomBindings(): Array<Type | Provider | any[]> {
|
||||
throw "Must set a root DOM adapter first.";
|
||||
}
|
||||
return [
|
||||
provide(DOCUMENT, {asValue: DOM.defaultDoc()}),
|
||||
provide(DOCUMENT, {useValue: DOM.defaultDoc()}),
|
||||
EventManager,
|
||||
new Provider(EVENT_MANAGER_PLUGINS, {toClass: DomEventsPlugin, multi: true}),
|
||||
new Provider(EVENT_MANAGER_PLUGINS, {toClass: KeyEventsPlugin, multi: true}),
|
||||
new Provider(EVENT_MANAGER_PLUGINS, {toClass: HammerGesturesPlugin, multi: true}),
|
||||
provide(DomRenderer, {asClass: DomRenderer_}),
|
||||
provide(Renderer, {asAlias: DomRenderer}),
|
||||
new Provider(EVENT_MANAGER_PLUGINS, {useClass: DomEventsPlugin, multi: true}),
|
||||
new Provider(EVENT_MANAGER_PLUGINS, {useClass: KeyEventsPlugin, multi: true}),
|
||||
new Provider(EVENT_MANAGER_PLUGINS, {useClass: HammerGesturesPlugin, multi: true}),
|
||||
provide(DomRenderer, {useClass: DomRenderer_}),
|
||||
provide(Renderer, {useExisting: DomRenderer}),
|
||||
DomSharedStylesHost,
|
||||
provide(SharedStylesHost, {asAlias: DomSharedStylesHost}),
|
||||
provide(SharedStylesHost, {useExisting: DomSharedStylesHost}),
|
||||
EXCEPTION_PROVIDER,
|
||||
provide(XHR, {asValue: new XHRImpl()}),
|
||||
provide(XHR, {useValue: new XHRImpl()}),
|
||||
Testability,
|
||||
BrowserDetails,
|
||||
AnimationBuilder,
|
||||
|
||||
@@ -50,7 +50,7 @@ import {Compiler_} from "./linker/compiler";
|
||||
* running on the page.
|
||||
*/
|
||||
export function platformBindings(): Array<Type | Provider | any[]> {
|
||||
return [provide(Reflector, {asValue: reflector}), TestabilityRegistry];
|
||||
return [provide(Reflector, {useValue: reflector}), TestabilityRegistry];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,10 +58,10 @@ export function platformBindings(): Array<Type | Provider | any[]> {
|
||||
*/
|
||||
function _componentProviders(appComponentType: Type): Array<Type | Provider | any[]> {
|
||||
return [
|
||||
provide(APP_COMPONENT, {asValue: appComponentType}),
|
||||
provide(APP_COMPONENT, {useValue: appComponentType}),
|
||||
provide(APP_COMPONENT_REF_PROMISE,
|
||||
{
|
||||
asFactory: (dynamicComponentLoader, injector: Injector) => {
|
||||
useFactory: (dynamicComponentLoader, injector: Injector) => {
|
||||
// TODO(rado): investigate whether to support bindings on root component.
|
||||
return dynamicComponentLoader.loadAsRoot(appComponentType, null, injector)
|
||||
.then((componentRef) => {
|
||||
@@ -77,7 +77,7 @@ function _componentProviders(appComponentType: Type): Array<Type | Provider | an
|
||||
}),
|
||||
provide(appComponentType,
|
||||
{
|
||||
asFactory: (p: Promise<any>) => p.then(ref => ref.instance),
|
||||
useFactory: (p: Promise<any>) => p.then(ref => ref.instance),
|
||||
deps: [APP_COMPONENT_REF_PROMISE]
|
||||
}),
|
||||
];
|
||||
@@ -89,24 +89,24 @@ function _componentProviders(appComponentType: Type): Array<Type | Provider | an
|
||||
*/
|
||||
export function applicationCommonBindings(): Array<Type | Provider | any[]> {
|
||||
return [
|
||||
provide(Compiler, {asClass: Compiler_}),
|
||||
provide(Compiler, {useClass: Compiler_}),
|
||||
APP_ID_RANDOM_PROVIDER,
|
||||
AppViewPool,
|
||||
provide(APP_VIEW_POOL_CAPACITY, {asValue: 10000}),
|
||||
provide(AppViewManager, {asClass: AppViewManager_}),
|
||||
provide(APP_VIEW_POOL_CAPACITY, {useValue: 10000}),
|
||||
provide(AppViewManager, {useClass: AppViewManager_}),
|
||||
AppViewManagerUtils,
|
||||
AppViewListener,
|
||||
ProtoViewFactory,
|
||||
ViewResolver,
|
||||
DEFAULT_PIPES,
|
||||
provide(IterableDiffers, {asValue: defaultIterableDiffers}),
|
||||
provide(KeyValueDiffers, {asValue: defaultKeyValueDiffers}),
|
||||
provide(IterableDiffers, {useValue: defaultIterableDiffers}),
|
||||
provide(KeyValueDiffers, {useValue: defaultKeyValueDiffers}),
|
||||
DirectiveResolver,
|
||||
PipeResolver,
|
||||
provide(DynamicComponentLoader, {asClass: DynamicComponentLoader_}),
|
||||
provide(DynamicComponentLoader, {useClass: DynamicComponentLoader_}),
|
||||
provide(LifeCycle,
|
||||
{
|
||||
asFactory: (exceptionHandler) => new LifeCycle_(null, assertionsEnabled()),
|
||||
useFactory: (exceptionHandler) => new LifeCycle_(null, assertionsEnabled()),
|
||||
deps: [ExceptionHandler]
|
||||
})
|
||||
];
|
||||
@@ -236,8 +236,8 @@ export class PlatformRef_ extends PlatformRef {
|
||||
var injector: Injector;
|
||||
var app: ApplicationRef;
|
||||
zone.run(() => {
|
||||
providers.push(provide(NgZone, {asValue: zone}));
|
||||
providers.push(provide(ApplicationRef, {asFactory: (): ApplicationRef => app, deps: []}));
|
||||
providers.push(provide(NgZone, {useValue: zone}));
|
||||
providers.push(provide(ApplicationRef, {useFactory: (): ApplicationRef => app, deps: []}));
|
||||
|
||||
var exceptionHandler;
|
||||
try {
|
||||
@@ -297,7 +297,7 @@ export abstract class ApplicationRef {
|
||||
* ```
|
||||
* var app = platform.application([applicationCommonBindings(), applicationDomBindings()];
|
||||
* app.bootstrap(FirstRootComponent);
|
||||
* app.bootstrap(SecondRootComponent, [provide(OverrideBinding, {asClass: OverriddenBinding})]);
|
||||
* app.bootstrap(SecondRootComponent, [provide(OverrideBinding, {useClass: OverriddenBinding})]);
|
||||
* ```
|
||||
*/
|
||||
abstract bootstrap(componentType: Type, bindings?: Array<Type | Provider | any[]>):
|
||||
|
||||
@@ -43,7 +43,7 @@ function _appIdRandomProviderFactory() {
|
||||
* Bindings that will generate a random APP_ID_TOKEN.
|
||||
*/
|
||||
export const APP_ID_RANDOM_PROVIDER: Provider =
|
||||
CONST_EXPR(new Provider(APP_ID, {toFactory: _appIdRandomProviderFactory, deps: []}));
|
||||
CONST_EXPR(new Provider(APP_ID, {useFactory: _appIdRandomProviderFactory, deps: []}));
|
||||
|
||||
function _randomChar(): string {
|
||||
return StringWrapper.fromCharCode(97 + Math.floor(Math.random() * 25));
|
||||
|
||||
@@ -56,7 +56,7 @@ export class IterableDiffers {
|
||||
*/
|
||||
static extend(factories: IterableDifferFactory[]): Provider {
|
||||
return new Provider(IterableDiffers, {
|
||||
toFactory: (parent: IterableDiffers) => {
|
||||
useFactory: (parent: IterableDiffers) => {
|
||||
if (isBlank(parent)) {
|
||||
// Typically would occur when calling IterableDiffers.extend inside of dependencies passed
|
||||
// to
|
||||
|
||||
@@ -56,7 +56,7 @@ export class KeyValueDiffers {
|
||||
*/
|
||||
static extend(factories: KeyValueDifferFactory[]): Provider {
|
||||
return new Provider(KeyValueDiffers, {
|
||||
toFactory: (parent: KeyValueDiffers) => {
|
||||
useFactory: (parent: KeyValueDiffers) => {
|
||||
if (isBlank(parent)) {
|
||||
// Typically would occur when calling KeyValueDiffers.extend inside of dependencies passed
|
||||
// to
|
||||
|
||||
@@ -42,16 +42,16 @@ export function compilerProviders(): Array<Type | Provider | any[]> {
|
||||
ChangeDetectionCompiler,
|
||||
provide(ChangeDetectorGenConfig,
|
||||
{
|
||||
asValue:
|
||||
useValue:
|
||||
new ChangeDetectorGenConfig(assertionsEnabled(), assertionsEnabled(), false, true)
|
||||
}),
|
||||
TemplateCompiler,
|
||||
provide(RuntimeCompiler, {asClass: RuntimeCompiler_}),
|
||||
provide(Compiler, {asAlias: RuntimeCompiler}),
|
||||
provide(RuntimeCompiler, {useClass: RuntimeCompiler_}),
|
||||
provide(Compiler, {useExisting: RuntimeCompiler}),
|
||||
DomElementSchemaRegistry,
|
||||
provide(ElementSchemaRegistry, {asAlias: DomElementSchemaRegistry}),
|
||||
provide(ElementSchemaRegistry, {useExisting: DomElementSchemaRegistry}),
|
||||
AnchorBasedAppRootUrl,
|
||||
provide(AppRootUrl, {asAlias: AnchorBasedAppRootUrl}),
|
||||
provide(AppRootUrl, {useExisting: AnchorBasedAppRootUrl}),
|
||||
UrlResolver
|
||||
];
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ export class DebugElementViewListener implements AppViewListener {
|
||||
|
||||
export const ELEMENT_PROBE_PROVIDERS: any[] = CONST_EXPR([
|
||||
DebugElementViewListener,
|
||||
CONST_EXPR(new Provider(AppViewListener, {toAlias: DebugElementViewListener})),
|
||||
CONST_EXPR(new Provider(AppViewListener, {useExisting: DebugElementViewListener})),
|
||||
]);
|
||||
|
||||
export const ELEMENT_PROBE_BINDINGS = ELEMENT_PROBE_PROVIDERS;
|
||||
@@ -91,8 +91,8 @@ export class NoProviderError extends AbstractProviderError {
|
||||
*
|
||||
* ```typescript
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* provide("one", {asFactory: (two) => "two", deps: [[new Inject("two")]]}),
|
||||
* provide("two", {asFactory: (one) => "one", deps: [[new Inject("one")]]})
|
||||
* provide("one", {useFactory: (two) => "two", deps: [[new Inject("two")]]}),
|
||||
* provide("two", {useFactory: (one) => "one", deps: [[new Inject("one")]]})
|
||||
* ]);
|
||||
*
|
||||
* expect(() => injector.get("one")).toThrowError();
|
||||
@@ -252,8 +252,8 @@ export class OutOfBoundsError extends BaseException {
|
||||
*
|
||||
* ```typescript
|
||||
* expect(() => Injector.resolveAndCreate([
|
||||
* new Provider("Strings", {toValue: "string1", multi: true}),
|
||||
* new Provider("Strings", {toValue: "string2", multi: false})
|
||||
* new Provider("Strings", {useValue: "string1", multi: true}),
|
||||
* new Provider("Strings", {useValue: "string2", multi: false})
|
||||
* ])).toThrowError();
|
||||
* ```
|
||||
*/
|
||||
|
||||
@@ -563,7 +563,7 @@ export class Injector {
|
||||
*
|
||||
* ```typescript
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* provide("validToken", {asValue: "Value"})
|
||||
* provide("validToken", {useValue: "Value"})
|
||||
* ]);
|
||||
* expect(injector.get("validToken")).toEqual("Value");
|
||||
* expect(() => injector.get("invalidToken")).toThrowError();
|
||||
@@ -588,7 +588,7 @@ export class Injector {
|
||||
*
|
||||
* ```typescript
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* provide("validToken", {asValue: "Value"})
|
||||
* provide("validToken", {useValue: "Value"})
|
||||
* ]);
|
||||
* expect(injector.getOptional("validToken")).toEqual("Value");
|
||||
* expect(injector.getOptional("invalidToken")).toBe(null);
|
||||
|
||||
@@ -17,7 +17,7 @@ import {CONST, CONST_EXPR, stringify, isBlank, isPresent} from "angular2/src/cor
|
||||
* }
|
||||
*
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* provide("MyEngine", {asClass: Engine}),
|
||||
* provide("MyEngine", {useClass: Engine}),
|
||||
* Car
|
||||
* ]);
|
||||
*
|
||||
|
||||
@@ -9,7 +9,7 @@ import {CONST} from 'angular2/src/core/facade/lang';
|
||||
* var t = new OpaqueToken("value");
|
||||
*
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* provide(t, {asValue: "providedValue"})
|
||||
* provide(t, {useValue: "providedValue"})
|
||||
* ]);
|
||||
*
|
||||
* expect(injector.get(t)).toEqual("bindingValue");
|
||||
|
||||
@@ -48,7 +48,7 @@ const _EMPTY_LIST = CONST_EXPR([]);
|
||||
*
|
||||
* ```javascript
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* new Provider("message", { toValue: 'Hello' })
|
||||
* new Provider("message", { useValue: 'Hello' })
|
||||
* ]);
|
||||
*
|
||||
* expect(injector.get("message")).toEqual('Hello');
|
||||
@@ -66,7 +66,8 @@ export class Provider {
|
||||
*
|
||||
* ### Example ([live demo](http://plnkr.co/edit/RSTG86qgmoxCyj9SWPwY?p=preview))
|
||||
*
|
||||
* Because `toAlias` and `toClass` are often confused, the example contains both use cases for
|
||||
* Because `useExisting` and `useClass` are often confused, the example contains both use cases
|
||||
* for
|
||||
* easy
|
||||
* comparison.
|
||||
*
|
||||
@@ -77,11 +78,11 @@ export class Provider {
|
||||
*
|
||||
* var injectorClass = Injector.resolveAndCreate([
|
||||
* Car,
|
||||
* new Provider(Vehicle, { toClass: Car })
|
||||
* new Provider(Vehicle, { useClass: Car })
|
||||
* ]);
|
||||
* var injectorAlias = Injector.resolveAndCreate([
|
||||
* Car,
|
||||
* new Provider(Vehicle, { toAlias: Car })
|
||||
* new Provider(Vehicle, { useExisting: Car })
|
||||
* ]);
|
||||
*
|
||||
* expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
|
||||
@@ -91,7 +92,7 @@ export class Provider {
|
||||
* expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
|
||||
* ```
|
||||
*/
|
||||
toClass: Type;
|
||||
useClass: Type;
|
||||
|
||||
/**
|
||||
* Binds a DI token to a value.
|
||||
@@ -100,23 +101,24 @@ export class Provider {
|
||||
*
|
||||
* ```javascript
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* new Provider("message", { toValue: 'Hello' })
|
||||
* new Provider("message", { useValue: 'Hello' })
|
||||
* ]);
|
||||
*
|
||||
* expect(injector.get("message")).toEqual('Hello');
|
||||
* ```
|
||||
*/
|
||||
toValue;
|
||||
useValue;
|
||||
|
||||
/**
|
||||
* Binds a DI token as an alias for an existing token.
|
||||
* Binds a DI token to an existing token.
|
||||
*
|
||||
* An alias means that {@link Injector} returns the same instance as if the alias token was used.
|
||||
* This is in contrast to `toClass` where a separate instance of `toClass` is returned.
|
||||
* {@link Injector} returns the same instance as if the provided token was used.
|
||||
* This is in contrast to `useClass` where a separate instance of `useClass` is returned.
|
||||
*
|
||||
* ### Example ([live demo](http://plnkr.co/edit/QsatsOJJ6P8T2fMe9gr8?p=preview))
|
||||
*
|
||||
* Because `toAlias` and `toClass` are often confused the example contains both use cases for easy
|
||||
* Because `useExisting` and `useClass` are often confused the example contains both use cases for
|
||||
* easy
|
||||
* comparison.
|
||||
*
|
||||
* ```typescript
|
||||
@@ -126,11 +128,11 @@ export class Provider {
|
||||
*
|
||||
* var injectorAlias = Injector.resolveAndCreate([
|
||||
* Car,
|
||||
* new Provider(Vehicle, { toAlias: Car })
|
||||
* new Provider(Vehicle, { useExisting: Car })
|
||||
* ]);
|
||||
* var injectorClass = Injector.resolveAndCreate([
|
||||
* Car,
|
||||
* new Provider(Vehicle, { toClass: Car })
|
||||
* new Provider(Vehicle, { useClass: Car })
|
||||
* ]);
|
||||
*
|
||||
* expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
|
||||
@@ -140,7 +142,7 @@ export class Provider {
|
||||
* expect(injectorClass.get(Vehicle) instanceof Car).toBe(true);
|
||||
* ```
|
||||
*/
|
||||
toAlias;
|
||||
useExisting;
|
||||
|
||||
/**
|
||||
* Binds a DI token to a function which computes the value.
|
||||
@@ -149,8 +151,8 @@ export class Provider {
|
||||
*
|
||||
* ```typescript
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* new Provider(Number, { toFactory: () => { return 1+2; }}),
|
||||
* new Provider(String, { toFactory: (value) => { return "Value: " + value; },
|
||||
* new Provider(Number, { useFactory: () => { return 1+2; }}),
|
||||
* new Provider(String, { useFactory: (value) => { return "Value: " + value; },
|
||||
* deps: [Number] })
|
||||
* ]);
|
||||
*
|
||||
@@ -160,7 +162,7 @@ export class Provider {
|
||||
*
|
||||
* Used in conjuction with dependencies.
|
||||
*/
|
||||
toFactory: Function;
|
||||
useFactory: Function;
|
||||
|
||||
/**
|
||||
* Specifies a set of dependencies
|
||||
@@ -170,8 +172,8 @@ export class Provider {
|
||||
*
|
||||
* ```typescript
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* new Provider(Number, { toFactory: () => { return 1+2; }}),
|
||||
* new Provider(String, { toFactory: (value) => { return "Value: " + value; },
|
||||
* new Provider(Number, { useFactory: () => { return 1+2; }}),
|
||||
* new Provider(String, { useFactory: (value) => { return "Value: " + value; },
|
||||
* deps: [Number] })
|
||||
* ]);
|
||||
*
|
||||
@@ -179,26 +181,26 @@ export class Provider {
|
||||
* expect(injector.get(String)).toEqual('Value: 3');
|
||||
* ```
|
||||
*
|
||||
* Used in conjunction with `toFactory`.
|
||||
* Used in conjunction with `useFactory`.
|
||||
*/
|
||||
dependencies: Object[];
|
||||
|
||||
/** @internal */
|
||||
_multi: boolean;
|
||||
|
||||
constructor(token, {toClass, toValue, toAlias, toFactory, deps, multi}: {
|
||||
toClass?: Type,
|
||||
toValue?: any,
|
||||
toAlias?: any,
|
||||
toFactory?: Function,
|
||||
constructor(token, {useClass, useValue, useExisting, useFactory, deps, multi}: {
|
||||
useClass?: Type,
|
||||
useValue?: any,
|
||||
useExisting?: any,
|
||||
useFactory?: Function,
|
||||
deps?: Object[],
|
||||
multi?: boolean
|
||||
}) {
|
||||
this.token = token;
|
||||
this.toClass = toClass;
|
||||
this.toValue = toValue;
|
||||
this.toAlias = toAlias;
|
||||
this.toFactory = toFactory;
|
||||
this.useClass = useClass;
|
||||
this.useValue = useValue;
|
||||
this.useExisting = useExisting;
|
||||
this.useFactory = useFactory;
|
||||
this.dependencies = deps;
|
||||
this._multi = multi;
|
||||
}
|
||||
@@ -216,8 +218,8 @@ export class Provider {
|
||||
*
|
||||
* ```typescript
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* new Provider("Strings", { toValue: "String1", multi: true}),
|
||||
* new Provider("Strings", { toValue: "String2", multi: true})
|
||||
* new Provider("Strings", { useValue: "String1", multi: true}),
|
||||
* new Provider("Strings", { useValue: "String2", multi: true})
|
||||
* ]);
|
||||
*
|
||||
* expect(injector.get("Strings")).toEqual(["String1", "String2"]);
|
||||
@@ -228,8 +230,8 @@ export class Provider {
|
||||
*
|
||||
* ```typescript
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* new Provider("Strings", { toValue: "String1", multi: true }),
|
||||
* new Provider("Strings", { toValue: "String2"})
|
||||
* new Provider("Strings", { useValue: "String1", multi: true }),
|
||||
* new Provider("Strings", { useValue: "String2"})
|
||||
* ]);
|
||||
* ```
|
||||
*/
|
||||
@@ -245,19 +247,37 @@ export class Binding extends Provider {
|
||||
toClass?: Type,
|
||||
toValue?: any,
|
||||
toAlias?: any,
|
||||
toFactory?: Function,
|
||||
deps?: Object[],
|
||||
multi?: boolean
|
||||
toFactory: Function, deps?: Object[], multi?: boolean
|
||||
}) {
|
||||
super(token, {
|
||||
toClass: toClass,
|
||||
toValue: toValue,
|
||||
toAlias: toAlias,
|
||||
toFactory: toFactory,
|
||||
useClass: toClass,
|
||||
useValue: toValue,
|
||||
useExisting: toAlias,
|
||||
useFactory: toFactory,
|
||||
deps: deps,
|
||||
multi: multi
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
get toClass() { return this.useClass; }
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
get toAlias() { return this.useExisting; }
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
get toFactory() { return this.useFactory; }
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
get toValue() { return this.useValue; }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,7 +290,7 @@ export class Binding extends Provider {
|
||||
* ### Example ([live demo](http://plnkr.co/edit/RfEnhh8kUEI0G3qsnIeT?p%3Dpreview&p=preview))
|
||||
*
|
||||
* ```typescript
|
||||
* var resolvedProviders = Injector.resolve([new Provider('message', {toValue: 'Hello'})]);
|
||||
* var resolvedProviders = Injector.resolve([new Provider('message', {useValue: 'Hello'})]);
|
||||
* var injector = Injector.fromResolvedProviders(resolvedProviders);
|
||||
*
|
||||
* expect(injector.get('message')).toEqual('Hello');
|
||||
@@ -327,7 +347,7 @@ export class ResolvedFactory {
|
||||
*
|
||||
* To construct a {@link Provider}, bind a `token` to either a class, a value, a factory function,
|
||||
* or
|
||||
* to an alias to another `token`.
|
||||
* to an existing `token`.
|
||||
* See {@link ProviderBuilder} for more details.
|
||||
*
|
||||
* The `token` is most commonly a class or {@link angular2/di/OpaqueToken}.
|
||||
@@ -343,19 +363,19 @@ export function bind(token): ProviderBuilder {
|
||||
*
|
||||
* <!-- TODO: improve the docs -->
|
||||
*/
|
||||
export function provide(token, {asClass, asValue, asAlias, asFactory, deps, multi}: {
|
||||
asClass?: Type,
|
||||
asValue?: any,
|
||||
asAlias?: any,
|
||||
asFactory?: Function,
|
||||
export function provide(token, {useClass, useValue, useExisting, useFactory, deps, multi}: {
|
||||
useClass?: Type,
|
||||
useValue?: any,
|
||||
useExisting?: any,
|
||||
useFactory?: Function,
|
||||
deps?: Object[],
|
||||
multi?: boolean
|
||||
}): Provider {
|
||||
return new Provider(token, {
|
||||
toClass: asClass,
|
||||
toValue: asValue,
|
||||
toAlias: asAlias,
|
||||
toFactory: asFactory,
|
||||
useClass: useClass,
|
||||
useValue: useValue,
|
||||
useExisting: useExisting,
|
||||
useFactory: useFactory,
|
||||
deps: deps,
|
||||
multi: multi
|
||||
});
|
||||
@@ -382,11 +402,11 @@ export class ProviderBuilder {
|
||||
*
|
||||
* var injectorClass = Injector.resolveAndCreate([
|
||||
* Car,
|
||||
* provide(Vehicle, {asClass: Car})
|
||||
* provide(Vehicle, {useClass: Car})
|
||||
* ]);
|
||||
* var injectorAlias = Injector.resolveAndCreate([
|
||||
* Car,
|
||||
* provide(Vehicle, {asAlias: Car})
|
||||
* provide(Vehicle, {useExisting: Car})
|
||||
* ]);
|
||||
*
|
||||
* expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
|
||||
@@ -401,7 +421,7 @@ export class ProviderBuilder {
|
||||
throw new BaseException(
|
||||
`Trying to create a class provider but "${stringify(type)}" is not a class!`);
|
||||
}
|
||||
return new Provider(this.token, {toClass: type});
|
||||
return new Provider(this.token, {useClass: type});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -411,19 +431,19 @@ export class ProviderBuilder {
|
||||
*
|
||||
* ```typescript
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* provide('message', {asValue: 'Hello'})
|
||||
* provide('message', {useValue: 'Hello'})
|
||||
* ]);
|
||||
*
|
||||
* expect(injector.get('message')).toEqual('Hello');
|
||||
* ```
|
||||
*/
|
||||
toValue(value: any): Provider { return new Provider(this.token, {toValue: value}); }
|
||||
toValue(value: any): Provider { return new Provider(this.token, {useValue: value}); }
|
||||
|
||||
/**
|
||||
* Binds a DI token as an alias for an existing token.
|
||||
* Binds a DI token to an existing token.
|
||||
*
|
||||
* An alias means that we will return the same instance as if the alias token was used. (This is
|
||||
* in contrast to `toClass` where a separate instance of `toClass` will be returned.)
|
||||
* Angular will return the same instance as if the provided token was used. (This is
|
||||
* in contrast to `useClass` where a separate instance of `useClass` will be returned.)
|
||||
*
|
||||
* ### Example ([live demo](http://plnkr.co/edit/uBaoF2pN5cfc5AfZapNw?p=preview))
|
||||
*
|
||||
@@ -438,11 +458,11 @@ export class ProviderBuilder {
|
||||
*
|
||||
* var injectorAlias = Injector.resolveAndCreate([
|
||||
* Car,
|
||||
* provide(Vehicle, {asAlias: Car})
|
||||
* provide(Vehicle, {useExisting: Car})
|
||||
* ]);
|
||||
* var injectorClass = Injector.resolveAndCreate([
|
||||
* Car,
|
||||
* provide(Vehicle, {asClass: Car})
|
||||
* provide(Vehicle, {useClass: Car})
|
||||
* ]);
|
||||
*
|
||||
* expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
|
||||
@@ -456,7 +476,7 @@ export class ProviderBuilder {
|
||||
if (isBlank(aliasToken)) {
|
||||
throw new BaseException(`Can not alias ${stringify(this.token)} to a blank value!`);
|
||||
}
|
||||
return new Provider(this.token, {toAlias: aliasToken});
|
||||
return new Provider(this.token, {useExisting: aliasToken});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -466,8 +486,8 @@ export class ProviderBuilder {
|
||||
*
|
||||
* ```typescript
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* provide(Number, {asFactory: () => { return 1+2; }}),
|
||||
* provide(String, {asFactory: (v) => { return "Value: " + v; }, deps: [Number]})
|
||||
* provide(Number, {useFactory: () => { return 1+2; }}),
|
||||
* provide(String, {useFactory: (v) => { return "Value: " + v; }, deps: [Number]})
|
||||
* ]);
|
||||
*
|
||||
* expect(injector.get(Number)).toEqual(3);
|
||||
@@ -479,7 +499,7 @@ export class ProviderBuilder {
|
||||
throw new BaseException(
|
||||
`Trying to create a factory provider but "${stringify(factory)}" is not a function!`);
|
||||
}
|
||||
return new Provider(this.token, {toFactory: factory, deps: dependencies});
|
||||
return new Provider(this.token, {useFactory: factory, deps: dependencies});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,18 +509,18 @@ export class ProviderBuilder {
|
||||
export function resolveFactory(provider: Provider): ResolvedFactory {
|
||||
var factoryFn: Function;
|
||||
var resolvedDeps;
|
||||
if (isPresent(provider.toClass)) {
|
||||
var toClass = resolveForwardRef(provider.toClass);
|
||||
factoryFn = reflector.factory(toClass);
|
||||
resolvedDeps = _dependenciesFor(toClass);
|
||||
} else if (isPresent(provider.toAlias)) {
|
||||
if (isPresent(provider.useClass)) {
|
||||
var useClass = resolveForwardRef(provider.useClass);
|
||||
factoryFn = reflector.factory(useClass);
|
||||
resolvedDeps = _dependenciesFor(useClass);
|
||||
} else if (isPresent(provider.useExisting)) {
|
||||
factoryFn = (aliasInstance) => aliasInstance;
|
||||
resolvedDeps = [Dependency.fromKey(Key.get(provider.toAlias))];
|
||||
} else if (isPresent(provider.toFactory)) {
|
||||
factoryFn = provider.toFactory;
|
||||
resolvedDeps = _constructDependencies(provider.toFactory, provider.dependencies);
|
||||
resolvedDeps = [Dependency.fromKey(Key.get(provider.useExisting))];
|
||||
} else if (isPresent(provider.useFactory)) {
|
||||
factoryFn = provider.useFactory;
|
||||
resolvedDeps = _constructDependencies(provider.useFactory, provider.dependencies);
|
||||
} else {
|
||||
factoryFn = () => provider.toValue;
|
||||
factoryFn = () => provider.useValue;
|
||||
resolvedDeps = _EMPTY_LIST;
|
||||
}
|
||||
return new ResolvedFactory(factoryFn, resolvedDeps);
|
||||
@@ -553,7 +573,7 @@ function _normalizeProviders(providers: Array<Type | Provider | ProviderBuilder
|
||||
Map<number, _NormalizedProvider | _NormalizedProvider[]> {
|
||||
providers.forEach(b => {
|
||||
if (b instanceof Type) {
|
||||
_normalizeProvider(provide(b, {asClass: b}), res);
|
||||
_normalizeProvider(provide(b, {useClass: b}), res);
|
||||
|
||||
} else if (b instanceof Provider) {
|
||||
_normalizeProvider(b, res);
|
||||
|
||||
@@ -27,7 +27,7 @@ class _ArrayLogger {
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* bootstrap(MyApp, [provide(ExceptionHandler, {asClass: MyExceptionHandler})])
|
||||
* bootstrap(MyApp, [provide(ExceptionHandler, {useClass: MyExceptionHandler})])
|
||||
*
|
||||
* ```
|
||||
*/
|
||||
|
||||
@@ -8,7 +8,7 @@ import {CONST_EXPR} from 'angular2/src/core/facade/lang';
|
||||
import {setProperty} from './shared';
|
||||
|
||||
const CHECKBOX_VALUE_ACCESSOR = CONST_EXPR(new Provider(
|
||||
NG_VALUE_ACCESSOR, {toAlias: forwardRef(() => CheckboxControlValueAccessor), multi: true}));
|
||||
NG_VALUE_ACCESSOR, {useExisting: forwardRef(() => CheckboxControlValueAccessor), multi: true}));
|
||||
|
||||
/**
|
||||
* The accessor for writing a value and listening to changes on a checkbox input element.
|
||||
|
||||
@@ -7,7 +7,7 @@ import {isBlank, CONST_EXPR} from 'angular2/src/core/facade/lang';
|
||||
import {setProperty} from './shared';
|
||||
|
||||
const DEFAULT_VALUE_ACCESSOR = CONST_EXPR(new Provider(
|
||||
NG_VALUE_ACCESSOR, {toAlias: forwardRef(() => DefaultValueAccessor), multi: true}));
|
||||
NG_VALUE_ACCESSOR, {useExisting: forwardRef(() => DefaultValueAccessor), multi: true}));
|
||||
|
||||
/**
|
||||
* The default accessor for writing a value and listening to changes that is used by the
|
||||
|
||||
@@ -10,7 +10,7 @@ import {ControlGroup} from '../model';
|
||||
import {Form} from './form_interface';
|
||||
|
||||
const controlGroupBinding =
|
||||
CONST_EXPR(new Provider(ControlContainer, {toAlias: forwardRef(() => NgControlGroup)}));
|
||||
CONST_EXPR(new Provider(ControlContainer, {useExisting: forwardRef(() => NgControlGroup)}));
|
||||
|
||||
/**
|
||||
* Creates and binds a control group to a DOM element.
|
||||
|
||||
@@ -14,7 +14,7 @@ import {Validators, NG_VALIDATORS} from '../validators';
|
||||
|
||||
|
||||
const controlNameBinding =
|
||||
CONST_EXPR(new Provider(NgControl, {toAlias: forwardRef(() => NgControlName)}));
|
||||
CONST_EXPR(new Provider(NgControl, {useExisting: forwardRef(() => NgControlName)}));
|
||||
|
||||
/**
|
||||
* Creates and binds a control with a specified name to a DOM element.
|
||||
|
||||
@@ -16,7 +16,7 @@ import {AbstractControl, ControlGroup, Control} from '../model';
|
||||
import {setUpControl} from './shared';
|
||||
|
||||
const formDirectiveProvider =
|
||||
CONST_EXPR(new Provider(ControlContainer, {toAlias: forwardRef(() => NgForm)}));
|
||||
CONST_EXPR(new Provider(ControlContainer, {useExisting: forwardRef(() => NgForm)}));
|
||||
|
||||
/**
|
||||
* If `NgForm` is bound in a component, `<form>` elements in that component will be
|
||||
|
||||
@@ -11,7 +11,7 @@ import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'
|
||||
import {setUpControl, isPropertyUpdated, selectValueAccessor} from './shared';
|
||||
|
||||
const formControlBinding =
|
||||
CONST_EXPR(new Provider(NgControl, {toAlias: forwardRef(() => NgFormControl)}));
|
||||
CONST_EXPR(new Provider(NgControl, {useExisting: forwardRef(() => NgFormControl)}));
|
||||
|
||||
/**
|
||||
* Binds an existing {@link Control} to a DOM element.
|
||||
|
||||
@@ -13,7 +13,7 @@ import {Control, ControlGroup} from '../model';
|
||||
import {setUpControl} from './shared';
|
||||
|
||||
const formDirectiveProvider =
|
||||
CONST_EXPR(new Provider(ControlContainer, {toAlias: forwardRef(() => NgFormModel)}));
|
||||
CONST_EXPR(new Provider(ControlContainer, {useExisting: forwardRef(() => NgFormModel)}));
|
||||
|
||||
/**
|
||||
* Binds an existing control group to a DOM element.
|
||||
|
||||
@@ -11,7 +11,7 @@ import {Validators, NG_VALIDATORS} from '../validators';
|
||||
import {setUpControl, isPropertyUpdated, selectValueAccessor} from './shared';
|
||||
|
||||
const formControlBinding =
|
||||
CONST_EXPR(new Provider(NgControl, {toAlias: forwardRef(() => NgModel)}));
|
||||
CONST_EXPR(new Provider(NgControl, {useExisting: forwardRef(() => NgModel)}));
|
||||
|
||||
/**
|
||||
* Binds a domain model to a form control.
|
||||
|
||||
@@ -9,7 +9,7 @@ import {CONST_EXPR} from 'angular2/src/core/facade/lang';
|
||||
import {setProperty} from './shared';
|
||||
|
||||
const SELECT_VALUE_ACCESSOR = CONST_EXPR(new Provider(
|
||||
NG_VALUE_ACCESSOR, {toAlias: forwardRef(() => SelectControlValueAccessor), multi: true}));
|
||||
NG_VALUE_ACCESSOR, {useExisting: forwardRef(() => SelectControlValueAccessor), multi: true}));
|
||||
|
||||
/**
|
||||
* Marks `<option>` as dynamic, so Angular can be notified when options change.
|
||||
|
||||
@@ -4,7 +4,7 @@ import {Directive} from 'angular2/src/core/metadata';
|
||||
import {Validators, NG_VALIDATORS} from '../validators';
|
||||
|
||||
const DEFAULT_VALIDATORS =
|
||||
CONST_EXPR(new Provider(NG_VALIDATORS, {toValue: Validators.required, multi: true}));
|
||||
CONST_EXPR(new Provider(NG_VALIDATORS, {useValue: Validators.required, multi: true}));
|
||||
|
||||
@Directive({
|
||||
selector: '[required][ng-control],[required][ng-form-control],[required][ng-model]',
|
||||
|
||||
@@ -174,7 +174,7 @@ export class DirectiveProvider extends ResolvedProvider_ {
|
||||
}
|
||||
|
||||
static createFromType(type: Type, annotation: DirectiveMetadata): DirectiveProvider {
|
||||
var provider = new Provider(type, {toClass: type});
|
||||
var provider = new Provider(type, {useClass: type});
|
||||
return DirectiveProvider.createFromProvider(provider, annotation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,4 +24,4 @@ const DEFAULT_PIPES_LIST = CONST_EXPR([
|
||||
export const DEFAULT_PIPES_TOKEN: OpaqueToken = CONST_EXPR(new OpaqueToken("Default Pipes"));
|
||||
|
||||
export const DEFAULT_PIPES: Provider =
|
||||
CONST_EXPR(new Provider(DEFAULT_PIPES_TOKEN, {toValue: DEFAULT_PIPES_LIST}));
|
||||
CONST_EXPR(new Provider(DEFAULT_PIPES_TOKEN, {useValue: DEFAULT_PIPES_LIST}));
|
||||
|
||||
@@ -10,7 +10,7 @@ export class PipeProvider extends ResolvedProvider_ {
|
||||
}
|
||||
|
||||
static createFromType(type: Type, metadata: PipeMetadata): PipeProvider {
|
||||
var provider = new Provider(type, {toClass: type});
|
||||
var provider = new Provider(type, {useClass: type});
|
||||
var rb = resolveProvider(provider);
|
||||
return new PipeProvider(metadata.name, metadata.pure, rb.key, rb.resolvedFactories,
|
||||
rb.multiProvider);
|
||||
|
||||
@@ -3,6 +3,6 @@ import {ExceptionHandler} from 'angular2/src/core/facade/exceptions';
|
||||
import {DOM} from 'angular2/src/core/dom/dom_adapter';
|
||||
|
||||
export const EXCEPTION_PROVIDER =
|
||||
provide(ExceptionHandler, {asFactory: () => new ExceptionHandler(DOM, false), deps: []});
|
||||
provide(ExceptionHandler, {useFactory: () => new ExceptionHandler(DOM, false), deps: []});
|
||||
|
||||
export const EXCEPTION_BINDING = EXCEPTION_PROVIDER;
|
||||
@@ -102,7 +102,7 @@ export class MockConnection implements Connection {
|
||||
* var connection;
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* MockBackend,
|
||||
* provide(Http, {asFactory: (backend, defaultOptions) => {
|
||||
* provide(Http, {useFactory: (backend, defaultOptions) => {
|
||||
* return new Http(backend, defaultOptions)
|
||||
* }, deps: [MockBackend, DefaultOptions]})]);
|
||||
* var http = injector.get(Http);
|
||||
@@ -137,7 +137,7 @@ export class MockBackend implements ConnectionBackend {
|
||||
* var text; //this will be set from mock response
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* MockBackend,
|
||||
* provide(Http, {asFactory: (backend, options) {
|
||||
* provide(Http, {useFactory: (backend, options) {
|
||||
* return new Http(backend, options);
|
||||
* }, deps: [MockBackend, BaseRequestOptions]}]);
|
||||
* var backend = injector.get(MockBackend);
|
||||
|
||||
@@ -95,7 +95,7 @@ export class XHRConnection implements Connection {
|
||||
* @Component({
|
||||
* viewProviders: [
|
||||
* HTTP_PROVIDERS,
|
||||
* provide(Http, {asFactory: (backend, options) => {
|
||||
* provide(Http, {useFactory: (backend, options) => {
|
||||
* return new Http(backend, options);
|
||||
* }, deps: [MyNodeBackend, BaseRequestOptions]})]
|
||||
* })
|
||||
|
||||
@@ -125,7 +125,7 @@ export class RequestOptions {
|
||||
* search: string = 'coreTeam=true';
|
||||
* }
|
||||
*
|
||||
* bootstrap(App, [HTTP_PROVIDERS, provide(RequestOptions, {asClass: MyOptions})]);
|
||||
* bootstrap(App, [HTTP_PROVIDERS, provide(RequestOptions, {useClass: MyOptions})]);
|
||||
* ```
|
||||
*
|
||||
* The options could also be extended when manually creating a {@link Request}
|
||||
|
||||
@@ -124,7 +124,7 @@ export class ResponseOptions {
|
||||
* headers:Headers = new Headers({network: 'github'});
|
||||
* }
|
||||
*
|
||||
* bootstrap(App, [HTTP_PROVIDERS, provide(ResponseOptions, {asClass: MyOptions})]);
|
||||
* bootstrap(App, [HTTP_PROVIDERS, provide(ResponseOptions, {useClass: MyOptions})]);
|
||||
* ```
|
||||
*
|
||||
* The options could also be extended when manually creating a {@link Response}
|
||||
|
||||
@@ -75,7 +75,7 @@ function mergeOptions(defaultOpts, providedOpts, method, url): RequestOptions {
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* BaseRequestOptions,
|
||||
* MockBackend,
|
||||
* provide(Http, {asFactory:
|
||||
* provide(Http, {useFactory:
|
||||
* function(backend, defaultOptions) {
|
||||
* return new Http(backend, defaultOptions);
|
||||
* },
|
||||
|
||||
@@ -30,7 +30,7 @@ import {OpaqueToken, Injectable, Optional, Inject} from 'angular2/angular2';
|
||||
* bootstrap(AppCmp, [
|
||||
* ROUTER_PROVIDERS,
|
||||
* PathLocationStrategy,
|
||||
* provide(APP_BASE_HREF, {asValue: '/my/app'})
|
||||
* provide(APP_BASE_HREF, {useValue: '/my/app'})
|
||||
* ]);
|
||||
* ```
|
||||
*/
|
||||
|
||||
@@ -44,7 +44,7 @@ import {LocationStrategy} from './location_strategy';
|
||||
*
|
||||
* bootstrap(AppCmp, [
|
||||
* ROUTER_PROVIDERS, // includes binding to PathLocationStrategy
|
||||
* provide(APP_BASE_HREF, {asValue: '/my/app'})
|
||||
* provide(APP_BASE_HREF, {useValue: '/my/app'})
|
||||
* ]);
|
||||
* ```
|
||||
*/
|
||||
|
||||
@@ -58,9 +58,9 @@ export class RouterOutlet {
|
||||
var childRouter = this._parentRouter.childRouter(componentType);
|
||||
|
||||
var providers = Injector.resolve([
|
||||
provide(ROUTE_DATA, {asValue: nextInstruction.routeData()}),
|
||||
provide(RouteParams, {asValue: new RouteParams(nextInstruction.params)}),
|
||||
provide(routerMod.Router, {asValue: childRouter})
|
||||
provide(ROUTE_DATA, {useValue: nextInstruction.routeData()}),
|
||||
provide(RouteParams, {useValue: new RouteParams(nextInstruction.params)}),
|
||||
provide(routerMod.Router, {useValue: childRouter})
|
||||
]);
|
||||
return this._loader.loadNextToLocation(componentType, this._elementRef, providers)
|
||||
.then((componentRef) => {
|
||||
|
||||
@@ -68,7 +68,7 @@ import {AppViewManager_} from "angular2/src/core/linker/view_manager";
|
||||
* @returns {any[]}
|
||||
*/
|
||||
function _getRootProviders() {
|
||||
return [provide(Reflector, {asValue: reflector})];
|
||||
return [provide(Reflector, {useValue: reflector})];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,36 +91,36 @@ function _getAppBindings() {
|
||||
return [
|
||||
compilerProviders(),
|
||||
provide(ChangeDetectorGenConfig,
|
||||
{asValue: new ChangeDetectorGenConfig(true, true, false, true)}),
|
||||
provide(DOCUMENT, {asValue: appDoc}),
|
||||
provide(DomRenderer, {asClass: DomRenderer_}),
|
||||
provide(Renderer, {asAlias: DomRenderer}),
|
||||
provide(APP_ID, {asValue: 'a'}),
|
||||
{useValue: new ChangeDetectorGenConfig(true, true, false, true)}),
|
||||
provide(DOCUMENT, {useValue: appDoc}),
|
||||
provide(DomRenderer, {useClass: DomRenderer_}),
|
||||
provide(Renderer, {useExisting: DomRenderer}),
|
||||
provide(APP_ID, {useValue: 'a'}),
|
||||
DomSharedStylesHost,
|
||||
provide(SharedStylesHost, {asAlias: DomSharedStylesHost}),
|
||||
provide(SharedStylesHost, {useExisting: DomSharedStylesHost}),
|
||||
AppViewPool,
|
||||
provide(AppViewManager, {asClass: AppViewManager_}),
|
||||
provide(AppViewManager, {useClass: AppViewManager_}),
|
||||
AppViewManagerUtils,
|
||||
Serializer,
|
||||
ELEMENT_PROBE_PROVIDERS,
|
||||
provide(APP_VIEW_POOL_CAPACITY, {asValue: 500}),
|
||||
provide(APP_VIEW_POOL_CAPACITY, {useValue: 500}),
|
||||
ProtoViewFactory,
|
||||
provide(DirectiveResolver, {asClass: MockDirectiveResolver}),
|
||||
provide(ViewResolver, {asClass: MockViewResolver}),
|
||||
provide(DirectiveResolver, {useClass: MockDirectiveResolver}),
|
||||
provide(ViewResolver, {useClass: MockViewResolver}),
|
||||
DEFAULT_PIPES,
|
||||
provide(IterableDiffers, {asValue: defaultIterableDiffers}),
|
||||
provide(KeyValueDiffers, {asValue: defaultKeyValueDiffers}),
|
||||
provide(IterableDiffers, {useValue: defaultIterableDiffers}),
|
||||
provide(KeyValueDiffers, {useValue: defaultKeyValueDiffers}),
|
||||
Log,
|
||||
provide(DynamicComponentLoader, {asClass: DynamicComponentLoader_}),
|
||||
provide(DynamicComponentLoader, {useClass: DynamicComponentLoader_}),
|
||||
PipeResolver,
|
||||
provide(ExceptionHandler, {asValue: new ExceptionHandler(DOM)}),
|
||||
provide(LocationStrategy, {asClass: MockLocationStrategy}),
|
||||
provide(ExceptionHandler, {useValue: new ExceptionHandler(DOM)}),
|
||||
provide(LocationStrategy, {useClass: MockLocationStrategy}),
|
||||
XHR,
|
||||
TestComponentBuilder,
|
||||
provide(NgZone, {asClass: MockNgZone}),
|
||||
provide(AnimationBuilder, {asClass: MockAnimationBuilder}),
|
||||
provide(NgZone, {useClass: MockNgZone}),
|
||||
provide(AnimationBuilder, {useClass: MockAnimationBuilder}),
|
||||
EventManager,
|
||||
new Provider(EVENT_MANAGER_PLUGINS, {toClass: DomEventsPlugin, multi: true})
|
||||
new Provider(EVENT_MANAGER_PLUGINS, {useClass: DomEventsPlugin, multi: true})
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -117,8 +117,8 @@ export function beforeEach(fn: FunctionWithParamTokens | SyncTestFn): void {
|
||||
* Example:
|
||||
*
|
||||
* beforeEachBindings(() => [
|
||||
* provide(Compiler, {asClass: MockCompiler}),
|
||||
* provide(SomeToken, {asValue: myValue}),
|
||||
* provide(Compiler, {useClass: MockCompiler}),
|
||||
* provide(SomeToken, {useValue: myValue}),
|
||||
* ]);
|
||||
*/
|
||||
export function beforeEachProviders(fn): void {
|
||||
@@ -148,7 +148,7 @@ function _it(jsmFn: Function, name: string, testFn: FunctionWithParamTokens | An
|
||||
if (testFn.hasToken(AsyncTestCompleter)) {
|
||||
jsmFn(name, (done) => {
|
||||
var completerProvider = provide(AsyncTestCompleter, {
|
||||
asFactory: () => {
|
||||
useFactory: () => {
|
||||
// Mark the test as async when an AsyncTestCompleter is injected in an it()
|
||||
if (!inIt) throw new Error('AsyncTestCompleter can only be injected in an "it()"');
|
||||
return new AsyncTestCompleter(done);
|
||||
|
||||
@@ -68,30 +68,30 @@ import {
|
||||
var _rootInjector: Injector;
|
||||
|
||||
// Contains everything that is safe to share between applications.
|
||||
var _rootProviders = [provide(Reflector, {asValue: reflector})];
|
||||
var _rootProviders = [provide(Reflector, {useValue: reflector})];
|
||||
|
||||
// TODO: This code is nearly identical to core/application. There should be a way to only write it
|
||||
// once
|
||||
function _injectorProviders(): any[] {
|
||||
return [
|
||||
provide(DOCUMENT, {asValue: DOM.defaultDoc()}),
|
||||
provide(DOCUMENT, {useValue: DOM.defaultDoc()}),
|
||||
EventManager,
|
||||
new Provider(EVENT_MANAGER_PLUGINS, {toClass: DomEventsPlugin, multi: true}),
|
||||
new Provider(EVENT_MANAGER_PLUGINS, {toClass: KeyEventsPlugin, multi: true}),
|
||||
new Provider(EVENT_MANAGER_PLUGINS, {toClass: HammerGesturesPlugin, multi: true}),
|
||||
provide(DomRenderer, {asClass: DomRenderer_}),
|
||||
provide(Renderer, {asAlias: DomRenderer}),
|
||||
new Provider(EVENT_MANAGER_PLUGINS, {useClass: DomEventsPlugin, multi: true}),
|
||||
new Provider(EVENT_MANAGER_PLUGINS, {useClass: KeyEventsPlugin, multi: true}),
|
||||
new Provider(EVENT_MANAGER_PLUGINS, {useClass: HammerGesturesPlugin, multi: true}),
|
||||
provide(DomRenderer, {useClass: DomRenderer_}),
|
||||
provide(Renderer, {useExisting: DomRenderer}),
|
||||
APP_ID_RANDOM_PROVIDER,
|
||||
DomSharedStylesHost,
|
||||
provide(SharedStylesHost, {asAlias: DomSharedStylesHost}),
|
||||
provide(SharedStylesHost, {useExisting: DomSharedStylesHost}),
|
||||
Serializer,
|
||||
provide(ON_WEB_WORKER, {asValue: false}),
|
||||
provide(ElementSchemaRegistry, {asValue: new DomElementSchemaRegistry()}),
|
||||
provide(ON_WEB_WORKER, {useValue: false}),
|
||||
provide(ElementSchemaRegistry, {useValue: new DomElementSchemaRegistry()}),
|
||||
RenderViewWithFragmentsStore,
|
||||
RenderProtoViewRefStore,
|
||||
AppViewPool,
|
||||
provide(APP_VIEW_POOL_CAPACITY, {asValue: 10000}),
|
||||
provide(AppViewManager, {asClass: AppViewManager_}),
|
||||
provide(APP_VIEW_POOL_CAPACITY, {useValue: 10000}),
|
||||
provide(AppViewManager, {useClass: AppViewManager_}),
|
||||
AppViewManagerUtils,
|
||||
AppViewListener,
|
||||
ProtoViewFactory,
|
||||
@@ -100,19 +100,19 @@ function _injectorProviders(): any[] {
|
||||
DirectiveResolver,
|
||||
Parser,
|
||||
Lexer,
|
||||
provide(ExceptionHandler, {asFactory: () => new ExceptionHandler(DOM), deps: []}),
|
||||
provide(XHR, {asValue: new XHRImpl()}),
|
||||
provide(ExceptionHandler, {useFactory: () => new ExceptionHandler(DOM), deps: []}),
|
||||
provide(XHR, {useValue: new XHRImpl()}),
|
||||
UrlResolver,
|
||||
provide(DynamicComponentLoader, {asClass: DynamicComponentLoader_}),
|
||||
provide(DynamicComponentLoader, {useClass: DynamicComponentLoader_}),
|
||||
Testability,
|
||||
AnchorBasedAppRootUrl,
|
||||
provide(AppRootUrl, {asAlias: AnchorBasedAppRootUrl}),
|
||||
provide(AppRootUrl, {useExisting: AnchorBasedAppRootUrl}),
|
||||
WebWorkerApplication,
|
||||
WebWorkerSetup,
|
||||
MessageBasedXHRImpl,
|
||||
MessageBasedRenderer,
|
||||
provide(ServiceMessageBrokerFactory, {asClass: ServiceMessageBrokerFactory_}),
|
||||
provide(ClientMessageBrokerFactory, {asClass: ClientMessageBrokerFactory_}),
|
||||
provide(ServiceMessageBrokerFactory, {useClass: ServiceMessageBrokerFactory_}),
|
||||
provide(ClientMessageBrokerFactory, {useClass: ClientMessageBrokerFactory_}),
|
||||
BrowserDetails,
|
||||
AnimationBuilder
|
||||
];
|
||||
@@ -120,8 +120,8 @@ function _injectorProviders(): any[] {
|
||||
|
||||
export function createInjector(zone: NgZone, bus: MessageBus): Injector {
|
||||
BrowserDomAdapter.makeCurrent();
|
||||
_rootProviders.push(provide(NgZone, {asValue: zone}));
|
||||
_rootProviders.push(provide(MessageBus, {asValue: bus}));
|
||||
_rootProviders.push(provide(NgZone, {useValue: zone}));
|
||||
_rootProviders.push(provide(MessageBus, {useValue: bus}));
|
||||
var injector: Injector = Injector.resolveAndCreate(_rootProviders);
|
||||
return injector.resolveAndCreateChild(_injectorProviders());
|
||||
}
|
||||
|
||||
@@ -96,18 +96,19 @@ function webWorkerProviders(appComponentType, bus: MessageBus, initData: {[key:
|
||||
return [
|
||||
compilerProviders(),
|
||||
Serializer,
|
||||
provide(MessageBus, {asValue: bus}),
|
||||
provide(ClientMessageBrokerFactory, {asClass: ClientMessageBrokerFactory_}),
|
||||
provide(ServiceMessageBrokerFactory, {asClass: ServiceMessageBrokerFactory_}),
|
||||
provide(MessageBus, {useValue: bus}),
|
||||
provide(ClientMessageBrokerFactory, {useClass: ClientMessageBrokerFactory_}),
|
||||
provide(ServiceMessageBrokerFactory, {useClass: ServiceMessageBrokerFactory_}),
|
||||
WebWorkerRenderer,
|
||||
provide(Renderer, {asAlias: WebWorkerRenderer}),
|
||||
provide(ON_WEB_WORKER, {asValue: true}),
|
||||
provide(Renderer, {useExisting: WebWorkerRenderer}),
|
||||
provide(ON_WEB_WORKER, {useValue: true}),
|
||||
RenderViewWithFragmentsStore,
|
||||
RenderProtoViewRefStore,
|
||||
provide(ExceptionHandler, {asFactory: () => new ExceptionHandler(new PrintLogger()), deps: []}),
|
||||
provide(ExceptionHandler,
|
||||
{useFactory: () => new ExceptionHandler(new PrintLogger()), deps: []}),
|
||||
WebWorkerXHRImpl,
|
||||
provide(XHR, {asAlias: WebWorkerXHRImpl}),
|
||||
provide(AppRootUrl, {asValue: new AppRootUrl(initData['rootUrl'])}),
|
||||
provide(XHR, {useExisting: WebWorkerXHRImpl}),
|
||||
provide(AppRootUrl, {useValue: new AppRootUrl(initData['rootUrl'])}),
|
||||
WebWorkerEventDispatcher,
|
||||
FORM_PROVIDERS
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user