feat(di): change the params of Provider and provide to start with "use"

Closes #4684
This commit is contained in:
vsavkin 2015-10-12 11:30:34 -07:00 committed by Victor Savkin
parent f443ecbfa6
commit 1aeafd31bd
110 changed files with 466 additions and 434 deletions

View File

@ -107,7 +107,7 @@ export {URLSearchParams} from './src/http/url_search_params';
* search: string = 'coreTeam=true';
* }
*
* bootstrap(App, [HTTP_PROVIDERS, provide(RequestOptions, {asClass: MyOptions})])
* bootstrap(App, [HTTP_PROVIDERS, provide(RequestOptions, {useClass: MyOptions})])
* .catch(err => console.error(err));
* ```
*
@ -125,7 +125,7 @@ export {URLSearchParams} from './src/http/url_search_params';
* var injector = Injector.resolveAndCreate([
* HTTP_PROVIDERS,
* MockBackend,
* provide(XHRBackend, {asAlias: MockBackend})
* provide(XHRBackend, {useExisting: MockBackend})
* ]);
* var http = injector.get(Http);
* var backend = injector.get(MockBackend);
@ -153,12 +153,12 @@ export const HTTP_PROVIDERS: any[] = [
// issue: https://github.com/angular/angular/issues/3183
provide(Http,
{
asFactory: (xhrBackend, requestOptions) => new Http(xhrBackend, requestOptions),
useFactory: (xhrBackend, requestOptions) => new Http(xhrBackend, requestOptions),
deps: [XHRBackend, RequestOptions]
}),
BrowserXhr,
provide(RequestOptions, {asClass: BaseRequestOptions}),
provide(ResponseOptions, {asClass: BaseResponseOptions}),
provide(RequestOptions, {useClass: BaseRequestOptions}),
provide(ResponseOptions, {useClass: BaseResponseOptions}),
XHRBackend
];
@ -230,7 +230,7 @@ export const HTTP_BINDINGS = HTTP_PROVIDERS;
* search: string = 'coreTeam=true';
* }
*
* bootstrap(App, [JSONP_PROVIDERS, provide(RequestOptions, {asClass: MyOptions})])
* bootstrap(App, [JSONP_PROVIDERS, provide(RequestOptions, {useClass: MyOptions})])
* .catch(err => console.error(err));
* ```
*
@ -247,7 +247,7 @@ export const HTTP_BINDINGS = HTTP_PROVIDERS;
* var injector = Injector.resolveAndCreate([
* JSONP_PROVIDERS,
* MockBackend,
* provide(JSONPBackend, {asAlias: MockBackend})
* provide(JSONPBackend, {useExisting: MockBackend})
* ]);
* var jsonp = injector.get(Jsonp);
* var backend = injector.get(MockBackend);
@ -275,13 +275,13 @@ export const JSONP_PROVIDERS: any[] = [
// issue: https://github.com/angular/angular/issues/3183
provide(Jsonp,
{
asFactory: (jsonpBackend, requestOptions) => new Jsonp(jsonpBackend, requestOptions),
useFactory: (jsonpBackend, requestOptions) => new Jsonp(jsonpBackend, requestOptions),
deps: [JSONPBackend, RequestOptions]
}),
BrowserJsonp,
provide(RequestOptions, {asClass: BaseRequestOptions}),
provide(ResponseOptions, {asClass: BaseResponseOptions}),
provide(JSONPBackend, {asClass: JSONPBackend_})
provide(RequestOptions, {useClass: BaseRequestOptions}),
provide(ResponseOptions, {useClass: BaseResponseOptions}),
provide(JSONPBackend, {useClass: JSONPBackend_})
];
/**

View File

@ -111,17 +111,17 @@ export const ROUTER_DIRECTIVES: any[] = CONST_EXPR([RouterOutlet, RouterLink]);
*/
export const ROUTER_PROVIDERS: any[] = CONST_EXPR([
RouteRegistry,
CONST_EXPR(new Provider(LocationStrategy, {toClass: PathLocationStrategy})),
CONST_EXPR(new Provider(LocationStrategy, {useClass: PathLocationStrategy})),
Location,
CONST_EXPR(
new Provider(Router,
{
toFactory: routerFactory,
useFactory: routerFactory,
deps: CONST_EXPR([RouteRegistry, Location, ROUTER_PRIMARY_COMPONENT])
})),
CONST_EXPR(new Provider(
ROUTER_PRIMARY_COMPONENT,
{toFactory: routerPrimaryComponentFactory, deps: CONST_EXPR([ApplicationRef])}))
{useFactory: routerPrimaryComponentFactory, deps: CONST_EXPR([ApplicationRef])}))
]);
/**

View File

@ -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,

View File

@ -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[]>):

View File

@ -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));

View File

@ -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

View File

@ -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

View File

@ -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
];
}

View File

@ -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;

View File

@ -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();
* ```
*/

View File

@ -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);

View File

@ -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
* ]);
*

View File

@ -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");

View File

@ -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);

View File

@ -27,7 +27,7 @@ class _ArrayLogger {
* }
* }
*
* bootstrap(MyApp, [provide(ExceptionHandler, {asClass: MyExceptionHandler})])
* bootstrap(MyApp, [provide(ExceptionHandler, {useClass: MyExceptionHandler})])
*
* ```
*/

View File

@ -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.

View File

@ -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

View File

@ -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.

View File

@ -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.

View File

@ -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

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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]',

View File

@ -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);
}
}

View File

@ -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}));

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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]})]
* })

View File

@ -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}

View File

@ -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}

View File

@ -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);
* },

View File

@ -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'})
* ]);
* ```
*/

View File

@ -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'})
* ]);
* ```
*/

View File

@ -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) => {

View File

@ -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})
];
}

View File

@ -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);

View File

@ -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());
}

View File

@ -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
];

View File

@ -89,7 +89,7 @@ export function main() {
DOM.appendChild(fakeDoc.body, el2);
DOM.appendChild(el, lightDom);
DOM.setText(lightDom, 'loading');
testProviders = [provide(DOCUMENT, {asValue: fakeDoc})];
testProviders = [provide(DOCUMENT, {useValue: fakeDoc})];
});
it('should throw if bootstrapped Directive is not a Component',
@ -98,7 +98,7 @@ export function main() {
var exceptionHandler = new ExceptionHandler(logger, false);
var refPromise =
bootstrap(HelloRootDirectiveIsNotCmp,
[testProviders, provide(ExceptionHandler, {asValue: exceptionHandler})]);
[testProviders, provide(ExceptionHandler, {useValue: exceptionHandler})]);
PromiseWrapper.then(refPromise, null, (exception) => {
expect(exception).toContainError(
@ -114,7 +114,7 @@ export function main() {
var exceptionHandler = new ExceptionHandler(logger, IS_DART ? false : true);
var refPromise =
bootstrap(HelloRootCmp, [provide(ExceptionHandler, {asValue: exceptionHandler})]);
bootstrap(HelloRootCmp, [provide(ExceptionHandler, {useValue: exceptionHandler})]);
PromiseWrapper.then(refPromise, null, (reason) => {
expect(reason.message).toContain('The selector "hello-app" did not match any elements');
async.done();
@ -129,7 +129,7 @@ export function main() {
var exceptionHandler = new ExceptionHandler(logger, IS_DART ? false : true);
var refPromise =
bootstrap(HelloRootCmp, [provide(ExceptionHandler, {asValue: exceptionHandler})]);
bootstrap(HelloRootCmp, [provide(ExceptionHandler, {useValue: exceptionHandler})]);
PromiseWrapper.then(refPromise, null, (reason) => {
expect(logger.res.join(""))
.toContain('The selector "hello-app" did not match any elements');
@ -166,7 +166,7 @@ export function main() {
it("should make the provided bindings available to the application component",
inject([AsyncTestCompleter], (async) => {
var refPromise = bootstrap(
HelloRootCmp3, [testProviders, provide("appBinding", {asValue: "BoundValue"})]);
HelloRootCmp3, [testProviders, provide("appBinding", {useValue: "BoundValue"})]);
refPromise.then((ref) => {
expect(ref.hostComponent.appBinding).toEqual("BoundValue");

View File

@ -50,7 +50,7 @@ export function main() {
it('should extend di-inherited diffesr', () => {
var parent = new IterableDiffers([factory1]);
var injector = Injector.resolveAndCreate([provide(IterableDiffers, {asValue: parent})]);
var injector = Injector.resolveAndCreate([provide(IterableDiffers, {useValue: parent})]);
var childInjector = injector.resolveAndCreateChild([IterableDiffers.extend([factory2])]);
expect(injector.get(IterableDiffers).factories).toEqual([factory1]);

View File

@ -84,7 +84,7 @@ export function main() {
describe('no jit', () => {
beforeEachBindings(() => [
provide(ChangeDetectorGenConfig,
{asValue: new ChangeDetectorGenConfig(true, true, false, false)})
{useValue: new ChangeDetectorGenConfig(true, true, false, false)})
]);
it('should watch element properties', () => {
expect(detectChanges(compiler, '<div [el-prop]="someProp">'))
@ -95,7 +95,7 @@ export function main() {
describe('jit', () => {
beforeEachBindings(() => [
provide(ChangeDetectorGenConfig,
{asValue: new ChangeDetectorGenConfig(true, true, false, true)})
{useValue: new ChangeDetectorGenConfig(true, true, false, true)})
]);
it('should watch element properties', () => {
expect(detectChanges(compiler, '<div [el-prop]="someProp">'))

View File

@ -39,7 +39,7 @@ export function main() {
protoViewFactorySpy = new SpyProtoViewFactory();
someProtoView = new AppProtoView(null, null, null, null, null, null);
protoViewFactorySpy.spy('createHost').andReturn(someProtoView);
return [provide(ProtoViewFactory, {asValue: protoViewFactorySpy})];
return [provide(ProtoViewFactory, {useValue: protoViewFactorySpy})];
});
it('should compile the template via TemplateCompiler',

View File

@ -51,7 +51,7 @@ export function main() {
beforeEachBindings(() => {
xhr = <any>new SpyXHR();
return [TEST_PROVIDERS, provide(XHR, {asValue: xhr})];
return [TEST_PROVIDERS, provide(XHR, {useValue: xhr})];
});
var compiler: StyleCompiler;

View File

@ -64,7 +64,7 @@ export function main() {
var compiler: TemplateCompiler;
var runtimeMetadataResolver: RuntimeMetadataResolver;
beforeEachBindings(() => [provide(APP_ID, {asValue: APP_ID_VALUE}), TEST_PROVIDERS]);
beforeEachBindings(() => [provide(APP_ID, {useValue: APP_ID_VALUE}), TEST_PROVIDERS]);
beforeEach(inject([TemplateCompiler, RuntimeMetadataResolver],
(_compiler, _runtimeMetadataResolver) => {
compiler = _compiler;

View File

@ -51,7 +51,7 @@ export function main() {
TEST_PROVIDERS,
provide(ElementSchemaRegistry,
{
asValue: new MockSchemaRegistry({'invalidProp': false},
useValue: new MockSchemaRegistry({'invalidProp': false},
{'mappedAttr': 'mappedProp'})
})
]);

View File

@ -5,6 +5,6 @@ import {MockXHR} from 'angular2/src/core/compiler/xhr_mock';
import {XHR} from 'angular2/src/core/compiler/xhr';
export var TEST_PROVIDERS = [
provide(ElementSchemaRegistry, {asValue: new MockSchemaRegistry({}, {})}),
provide(XHR, {asClass: MockXHR})
provide(ElementSchemaRegistry, {useValue: new MockSchemaRegistry({}, {})}),
provide(XHR, {useClass: MockXHR})
];

View File

@ -28,7 +28,7 @@ class MyComp {
export function main() {
describe('element probe', function() {
beforeEachBindings(() => [provide(APP_VIEW_POOL_CAPACITY, {asValue: 0})]);
beforeEachBindings(() => [provide(APP_VIEW_POOL_CAPACITY, {useValue: 0})]);
it('should return a TestElement from a dom element',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {

View File

@ -90,17 +90,17 @@ class NoAnnotations {
export function main() {
var dynamicProviders = [
provide('provider0', {asValue: 1}),
provide('provider1', {asValue: 1}),
provide('provider2', {asValue: 1}),
provide('provider3', {asValue: 1}),
provide('provider4', {asValue: 1}),
provide('provider5', {asValue: 1}),
provide('provider6', {asValue: 1}),
provide('provider7', {asValue: 1}),
provide('provider8', {asValue: 1}),
provide('provider9', {asValue: 1}),
provide('provider10', {asValue: 1})
provide('provider0', {useValue: 1}),
provide('provider1', {useValue: 1}),
provide('provider2', {useValue: 1}),
provide('provider3', {useValue: 1}),
provide('provider4', {useValue: 1}),
provide('provider5', {useValue: 1}),
provide('provider6', {useValue: 1}),
provide('provider7', {useValue: 1}),
provide('provider8', {useValue: 1}),
provide('provider9', {useValue: 1}),
provide('provider10', {useValue: 1})
];
[{strategy: 'inline', providers: [], strategyClass: InjectorInlineStrategy},
@ -158,7 +158,7 @@ export function main() {
});
it('should provide to a value', () => {
var injector = createInjector([provide(Engine, {asValue: "fake engine"})]);
var injector = createInjector([provide(Engine, {useValue: "fake engine"})]);
var engine = injector.get(Engine);
expect(engine).toEqual("fake engine");
@ -168,7 +168,7 @@ export function main() {
function sportsCarFactory(e) { return new SportsCar(e); }
var injector =
createInjector([Engine, provide(Car, {asFactory: sportsCarFactory, deps: [Engine]})]);
createInjector([Engine, provide(Car, {useFactory: sportsCarFactory, deps: [Engine]})]);
var car = injector.get(Car);
expect(car).toBeAnInstanceOf(SportsCar);
@ -176,14 +176,17 @@ export function main() {
});
it('should supporting provider to null', () => {
var injector = createInjector([provide(Engine, {asValue: null})]);
var injector = createInjector([provide(Engine, {useValue: null})]);
var engine = injector.get(Engine);
expect(engine).toBeNull();
});
it('should provide to an alias', () => {
var injector = createInjector(
[Engine, provide(SportsCar, {asClass: SportsCar}), provide(Car, {asAlias: SportsCar})]);
var injector = createInjector([
Engine,
provide(SportsCar, {useClass: SportsCar}),
provide(Car, {useExisting: SportsCar})
]);
var car = injector.get(Car);
var sportsCar = injector.get(SportsCar);
@ -194,8 +197,8 @@ export function main() {
it('should support multiProviders', () => {
var injector = createInjector([
Engine,
new Provider(Car, {toClass: SportsCar, multi: true}),
new Provider(Car, {toClass: CarWithOptionalEngine, multi: true})
new Provider(Car, {useClass: SportsCar, multi: true}),
new Provider(Car, {useClass: CarWithOptionalEngine, multi: true})
]);
var cars = injector.get(Car);
@ -204,9 +207,9 @@ export function main() {
expect(cars[1]).toBeAnInstanceOf(CarWithOptionalEngine);
});
it('should support multiProviders that are created using toAlias', () => {
it('should support multiProviders that are created using useExisting', () => {
var injector = createInjector(
[Engine, SportsCar, new Provider(Car, {toAlias: SportsCar, multi: true})]);
[Engine, SportsCar, new Provider(Car, {useExisting: SportsCar, multi: true})]);
var cars = injector.get(Car);
expect(cars.length).toEqual(1);
@ -214,22 +217,22 @@ export function main() {
});
it('should throw when the aliased provider does not exist', () => {
var injector = createInjector([provide('car', {asAlias: SportsCar})]);
var injector = createInjector([provide('car', {useExisting: SportsCar})]);
var e = `No provider for ${stringify(SportsCar)}! (car -> ${stringify(SportsCar)})`;
expect(() => injector.get('car')).toThrowError(e);
});
it('should handle forwardRef in toAlias', () => {
it('should handle forwardRef in useExisting', () => {
var injector = createInjector([
provide('originalEngine', {asClass: forwardRef(() => Engine)}),
provide('aliasedEngine', {asAlias:<any>forwardRef(() => 'originalEngine')})
provide('originalEngine', {useClass: forwardRef(() => Engine)}),
provide('aliasedEngine', {useExisting:<any>forwardRef(() => 'originalEngine')})
]);
expect(injector.get('aliasedEngine')).toBeAnInstanceOf(Engine);
});
it('should support overriding factory dependencies', () => {
var injector = createInjector(
[Engine, provide(Car, {asFactory: (e) => new SportsCar(e), deps: [Engine]})]);
[Engine, provide(Car, {useFactory: (e) => new SportsCar(e), deps: [Engine]})]);
var car = injector.get(Car);
expect(car).toBeAnInstanceOf(SportsCar);
@ -252,13 +255,13 @@ export function main() {
it("should use the last provider when there are multiple providers for same token", () => {
var injector = createInjector(
[provide(Engine, {asClass: Engine}), provide(Engine, {asClass: TurboEngine})]);
[provide(Engine, {useClass: Engine}), provide(Engine, {useClass: TurboEngine})]);
expect(injector.get(Engine)).toBeAnInstanceOf(TurboEngine);
});
it('should use non-type tokens', () => {
var injector = createInjector([provide('token', {asValue: 'value'})]);
var injector = createInjector([provide('token', {useValue: 'value'})]);
expect(injector.get('token')).toEqual('value');
});
@ -289,7 +292,7 @@ export function main() {
});
it('should throw when trying to instantiate a cyclic dependency', () => {
var injector = createInjector([Car, provide(Engine, {asClass: CyclicEngine})]);
var injector = createInjector([Car, provide(Engine, {useClass: CyclicEngine})]);
expect(() => injector.get(Car))
.toThrowError(
@ -297,7 +300,7 @@ export function main() {
});
it('should show the full path when error happens in a constructor', () => {
var providers = Injector.resolve([Car, provide(Engine, {asClass: BrokenEngine})]);
var providers = Injector.resolve([Car, provide(Engine, {useClass: BrokenEngine})]);
var proto = new ProtoInjector([
new ProviderWithVisibility(providers[0], Visibility.Public),
new ProviderWithVisibility(providers[1], Visibility.Public)
@ -316,7 +319,7 @@ export function main() {
});
it('should provide context when throwing an exception ', () => {
var engineProvider = Injector.resolve([provide(Engine, {asClass: BrokenEngine})])[0];
var engineProvider = Injector.resolve([provide(Engine, {useClass: BrokenEngine})])[0];
var protoParent =
new ProtoInjector([new ProviderWithVisibility(engineProvider, Visibility.Public)]);
@ -340,7 +343,7 @@ export function main() {
var injector = createInjector([
Car,
provide(Engine, {asFactory: (() => isBroken ? new BrokenEngine() : new Engine())})
provide(Engine, {useFactory: (() => isBroken ? new BrokenEngine() : new Engine())})
]);
expect(() => injector.get(Car)).toThrowError(new RegExp("Error"));
@ -351,7 +354,7 @@ export function main() {
});
it('should support null values', () => {
var injector = createInjector([provide('null', {asValue: null})]);
var injector = createInjector([provide('null', {useValue: null})]);
expect(injector.get('null')).toBe(null);
});
@ -388,7 +391,7 @@ export function main() {
it("should not use the child providers when resolving the dependencies of a parent provider",
() => {
var parent = Injector.resolveAndCreate([Car, Engine]);
var child = parent.resolveAndCreateChild([provide(Engine, {asClass: TurboEngine})]);
var child = parent.resolveAndCreateChild([provide(Engine, {useClass: TurboEngine})]);
var carFromChild = child.get(Car);
expect(carFromChild.engine).toBeAnInstanceOf(Engine);
@ -396,7 +399,7 @@ export function main() {
it('should create new instance in a child injector', () => {
var parent = Injector.resolveAndCreate([Engine]);
var child = parent.resolveAndCreateChild([provide(Engine, {asClass: TurboEngine})]);
var child = parent.resolveAndCreateChild([provide(Engine, {useClass: TurboEngine})]);
var engineFromParent = parent.get(Engine);
var engineFromChild = child.get(Engine);
@ -441,7 +444,7 @@ export function main() {
it("should return a dependency from self", () => {
var inj = Injector.resolveAndCreate([
Engine,
provide(Car, {asFactory: (e) => new Car(e), deps: [[Engine, new SelfMetadata()]]})
provide(Car, {useFactory: (e) => new Car(e), deps: [[Engine, new SelfMetadata()]]})
]);
expect(inj.get(Car)).toBeAnInstanceOf(Car);
@ -449,8 +452,9 @@ export function main() {
it("should throw when not requested provider on self", () => {
var parent = Injector.resolveAndCreate([Engine]);
var child = parent.resolveAndCreateChild(
[provide(Car, {asFactory: (e) => new Car(e), deps: [[Engine, new SelfMetadata()]]})]);
var child = parent.resolveAndCreateChild([
provide(Car, {useFactory: (e) => new Car(e), deps: [[Engine, new SelfMetadata()]]})
]);
expect(() => child.get(Car))
.toThrowError(`No provider for Engine! (${stringify(Car)} -> ${stringify(Engine)})`);
@ -460,8 +464,9 @@ export function main() {
describe("@Host()", () => {
it("should return a dependency from same host", () => {
var parent = Injector.resolveAndCreate([Engine]);
var child = parent.resolveAndCreateChild(
[provide(Car, {asFactory: (e) => new Car(e), deps: [[Engine, new HostMetadata()]]})]);
var child = parent.resolveAndCreateChild([
provide(Car, {useFactory: (e) => new Car(e), deps: [[Engine, new HostMetadata()]]})
]);
expect(child.get(Car)).toBeAnInstanceOf(Car);
});
@ -472,8 +477,9 @@ export function main() {
new ProtoInjector([new ProviderWithVisibility(engine, Visibility.Private)]);
var parent = new Injector(protoParent);
var child = Injector.resolveAndCreate(
[provide(Car, {asFactory: (e) => new Car(e), deps: [[Engine, new HostMetadata()]]})]);
var child = Injector.resolveAndCreate([
provide(Car, {useFactory: (e) => new Car(e), deps: [[Engine, new HostMetadata()]]})
]);
child.internalStrategy.attach(parent, true); // host
@ -486,8 +492,9 @@ export function main() {
new ProtoInjector([new ProviderWithVisibility(engine, Visibility.Public)]);
var parent = new Injector(protoParent);
var child = Injector.resolveAndCreate(
[provide(Car, {asFactory: (e) => new Car(e), deps: [[Engine, new HostMetadata()]]})]);
var child = Injector.resolveAndCreate([
provide(Car, {useFactory: (e) => new Car(e), deps: [[Engine, new HostMetadata()]]})
]);
child.internalStrategy.attach(parent, true); // host
@ -498,8 +505,8 @@ export function main() {
it("should not skip self", () => {
var parent = Injector.resolveAndCreate([Engine]);
var child = parent.resolveAndCreateChild([
provide(Engine, {asClass: TurboEngine}),
provide(Car, {asFactory: (e) => new Car(e), deps: [[Engine, new HostMetadata()]]})
provide(Engine, {useClass: TurboEngine}),
provide(Car, {useFactory: (e) => new Car(e), deps: [[Engine, new HostMetadata()]]})
]);
expect(child.get(Car).engine).toBeAnInstanceOf(TurboEngine);
@ -514,9 +521,9 @@ export function main() {
var parent = new Injector(protoParent);
var child = Injector.resolveAndCreate([
provide(Engine, {asClass: BrokenEngine}),
provide(Engine, {useClass: BrokenEngine}),
provide(Car,
{asFactory: (e) => new Car(e), deps: [[Engine, new SkipSelfMetadata()]]})
{useFactory: (e) => new Car(e), deps: [[Engine, new SkipSelfMetadata()]]})
]);
child.internalStrategy.attach(parent, true); // boundary
@ -530,9 +537,9 @@ export function main() {
var parent = new Injector(protoParent);
var child = Injector.resolveAndCreate([
provide(Engine, {asClass: BrokenEngine}),
provide(Engine, {useClass: BrokenEngine}),
provide(Car,
{asFactory: (e) => new Car(e), deps: [[Engine, new SkipSelfMetadata()]]})
{useFactory: (e) => new Car(e), deps: [[Engine, new SkipSelfMetadata()]]})
]);
child.internalStrategy.attach(parent, true); // boundary
@ -546,9 +553,9 @@ export function main() {
var parent = new Injector(protoParent);
var child = Injector.resolveAndCreate([
provide(Engine, {asClass: BrokenEngine}),
provide(Engine, {useClass: BrokenEngine}),
provide(Car,
{asFactory: (e) => new Car(e), deps: [[Engine, new SkipSelfMetadata()]]})
{useFactory: (e) => new Car(e), deps: [[Engine, new SkipSelfMetadata()]]})
]);
child.internalStrategy.attach(parent, false);
@ -559,8 +566,8 @@ export function main() {
it("should not skip self", () => {
var parent = Injector.resolveAndCreate([Engine]);
var child = parent.resolveAndCreateChild([
provide(Engine, {asClass: TurboEngine}),
provide(Car, {asFactory: (e) => new Car(e), deps: [Engine]})
provide(Engine, {useClass: TurboEngine}),
provide(Car, {useFactory: (e) => new Car(e), deps: [Engine]})
]);
expect(child.get(Car).engine).toBeAnInstanceOf(TurboEngine);
@ -579,8 +586,8 @@ export function main() {
it("should support multi providers", () => {
var provider = Injector.resolve([
new Provider(Engine, {toClass: BrokenEngine, multi: true}),
new Provider(Engine, {toClass: TurboEngine, multi: true})
new Provider(Engine, {useClass: BrokenEngine, multi: true}),
new Provider(Engine, {useClass: TurboEngine, multi: true})
])[0];
expect(provider.key.token).toBe(Engine);
@ -590,7 +597,7 @@ export function main() {
it("should support multi providers with only one provider", () => {
var provider =
Injector.resolve([new Provider(Engine, {toClass: BrokenEngine, multi: true})])[0];
Injector.resolve([new Provider(Engine, {useClass: BrokenEngine, multi: true})])[0];
expect(provider.key.token).toBe(Engine);
expect(provider.multiProvider).toEqual(true);
@ -599,20 +606,20 @@ export function main() {
it("should throw when mixing multi providers with regular providers", () => {
expect(() => {
Injector.resolve([new Provider(Engine, {toClass: BrokenEngine, multi: true}), Engine]);
Injector.resolve([new Provider(Engine, {useClass: BrokenEngine, multi: true}), Engine]);
}).toThrowErrorWith("Cannot mix multi providers and regular providers");
expect(() => {
Injector.resolve([Engine, new Provider(Engine, {toClass: BrokenEngine, multi: true})]);
Injector.resolve([Engine, new Provider(Engine, {useClass: BrokenEngine, multi: true})]);
}).toThrowErrorWith("Cannot mix multi providers and regular providers");
});
it('should resolve forward references', () => {
var providers = Injector.resolve([
forwardRef(() => Engine),
[provide(forwardRef(() => BrokenEngine), {asClass: forwardRef(() => Engine)})],
[provide(forwardRef(() => BrokenEngine), {useClass: forwardRef(() => Engine)})],
provide(forwardRef(() => String),
{asFactory: () => 'OK', deps: [forwardRef(() => Engine)]})
{useFactory: () => 'OK', deps: [forwardRef(() => Engine)]})
]);
var engineProvider = providers[0];
@ -628,7 +635,7 @@ export function main() {
var providers = Injector.resolve([
provide("token",
{
asFactory: (e) => "result",
useFactory: (e) => "result",
deps: [[new InjectMetadata("dep"), new CustomDependencyMetadata()]]
})
]);

View File

@ -29,7 +29,7 @@ export function main() {
describe('binding to CSS class list', () => {
describe('viewpool support', () => {
beforeEachBindings(() => { return [provide(APP_VIEW_POOL_CAPACITY, {asValue: 100})]; });
beforeEachBindings(() => { return [provide(APP_VIEW_POOL_CAPACITY, {useValue: 100})]; });
it('should clean up when the directive is destroyed',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {

View File

@ -37,8 +37,8 @@ export function main() {
protoViewFactorySpy = new SpyProtoViewFactory();
someProtoView = new AppProtoView(null, null, null, null, null, null);
protoViewFactorySpy.spy('createHost').andReturn(someProtoView);
var factory = provide(ProtoViewFactory, {asValue: protoViewFactorySpy});
var classProvider = provide(Compiler, {asClass: Compiler_});
var factory = provide(ProtoViewFactory, {useValue: protoViewFactorySpy});
var classProvider = provide(Compiler, {useClass: Compiler_});
var providers = [factory, classProvider];
return providers;
});

View File

@ -232,7 +232,7 @@ export function main() {
var dynamicProviders = [];
for (var i = 0; i < 20; i++) {
dynamicProviders.push(provide(i, {asValue: i}));
dynamicProviders.push(provide(i, {useValue: i}));
}
function createPei(parent, index, providers: any[], distance = 1, hasShadowRoot = false, dirVariableBindings = null) {
@ -322,7 +322,7 @@ export function main() {
describe('inline strategy', () => {
it("should allow for direct access using getProviderAtIndex", () => {
var proto = createPei(null, 0, [provide(SimpleDirective, {asClass: SimpleDirective})]);
var proto = createPei(null, 0, [provide(SimpleDirective, {useClass: SimpleDirective})]);
expect(proto.getProviderAtIndex(0)).toBeAnInstanceOf(DirectiveProvider);
expect(() => proto.getProviderAtIndex(-1)).toThrowError('Index -1 is out-of-bounds.');
@ -373,9 +373,9 @@ export function main() {
var pei = createPei(null, 0, [
DirectiveProvider.createFromType(
SimpleDirective,
new ComponentMetadata({providers: [provide('injectable1', {asValue: 'injectable1'})]})),
new ComponentMetadata({providers: [provide('injectable1', {useValue: 'injectable1'})]})),
DirectiveProvider.createFromType(SomeOtherDirective, new ComponentMetadata({
providers: [provide('injectable2', {asValue: 'injectable2'})]
providers: [provide('injectable2', {useValue: 'injectable2'})]
}))
]);
@ -388,7 +388,7 @@ export function main() {
it("should collect view providers from the component", () => {
var pei = createPei(null, 0,
[DirectiveProvider.createFromType(SimpleDirective, new ComponentMetadata({
viewProviders: [provide('injectable1', {asValue: 'injectable1'})]
viewProviders: [provide('injectable1', {useValue: 'injectable1'})]
}))],
0, true);
@ -401,8 +401,8 @@ export function main() {
DirectiveProvider.createFromType(
SimpleDirective,
new ComponentMetadata({
viewProviders: [[[provide('view', {asValue: 'view'})]]],
providers: [[[provide('host', {asValue: 'host'})]]]
viewProviders: [[[provide('view', {useValue: 'view'})]]],
providers: [[[provide('host', {useValue: 'host'})]]]
}))
], 0, true);
@ -510,13 +510,13 @@ export function main() {
var childInj = parentChildInjectors(
ListWrapper.concat(
[DirectiveProvider.createFromType(SimpleDirective, new ComponentMetadata({
providers: [provide('injectable1', {asValue: 'injectable1'})]
providers: [provide('injectable1', {useValue: 'injectable1'})]
}))],
extraProviders),
[DirectiveProvider.createFromType(SimpleDirective, new ComponentMetadata({
providers: [
provide('injectable1', {asValue:'new-injectable1'}),
provide('injectable2', {asFactory:
provide('injectable1', {useValue:'new-injectable1'}),
provide('injectable2', {useFactory:
(val) => `${val}-injectable2`,
deps: [[new InjectMetadata('injectable1'), new SkipSelfMetadata()]]})
]
@ -526,8 +526,8 @@ export function main() {
it("should instantiate providers that have dependencies", () => {
var providers = [
provide('injectable1', {asValue: 'injectable1'}),
provide('injectable2', {asFactory:
provide('injectable1', {useValue: 'injectable1'}),
provide('injectable2', {useFactory:
(val) => `${val}-injectable2`,
deps: ['injectable1']})
];
@ -542,8 +542,8 @@ export function main() {
it("should instantiate viewProviders that have dependencies", () => {
var viewProviders = [
provide('injectable1', {asValue: 'injectable1'}),
provide('injectable2', {asFactory:
provide('injectable1', {useValue: 'injectable1'}),
provide('injectable2', {useFactory:
(val) => `${val}-injectable2`,
deps: ['injectable1']})
];
@ -559,7 +559,7 @@ export function main() {
it("should instantiate components that depend on viewProviders providers", () => {
var inj = injector(
ListWrapper.concat([DirectiveProvider.createFromType(NeedsService, new ComponentMetadata({
viewProviders: [provide('service', {asValue: 'service'})]
viewProviders: [provide('service', {useValue: 'service'})]
}))],
extraProviders),
null, true);
@ -570,7 +570,7 @@ export function main() {
var created = false;
var inj = injector(
ListWrapper.concat([DirectiveProvider.createFromType(SimpleDirective, new ComponentMetadata({
providers: [provide('service', {asFactory: () => created = true})]
providers: [provide('service', {useFactory: () => created = true})]
}))],
extraProviders),
null, true);
@ -586,7 +586,7 @@ export function main() {
var created = false;
var inj = injector(
ListWrapper.concat([DirectiveProvider.createFromType(SimpleDirective, new ComponentMetadata({
viewProviders: [provide('service', {asFactory: () => created = true})]
viewProviders: [provide('service', {useFactory: () => created = true})]
}))],
extraProviders),
null, true);
@ -601,7 +601,7 @@ export function main() {
it("should not instantiate other directives that depend on viewProviders providers",
() => {
var directiveAnnotation = new ComponentMetadata({
viewProviders: ListWrapper.concat([provide("service", {asValue: "service"})], extraProviders)
viewProviders: ListWrapper.concat([provide("service", {useValue: "service"})], extraProviders)
});
var componentDirective =
DirectiveProvider.createFromType(SimpleDirective, directiveAnnotation);
@ -613,7 +613,7 @@ export function main() {
it("should instantiate directives that depend on providers of other directives", () => {
var shadowInj = hostShadowInjectors(
ListWrapper.concat([DirectiveProvider.createFromType(SimpleDirective, new ComponentMetadata({
providers: [provide('service', {asValue: 'hostService'})]})
providers: [provide('service', {useValue: 'hostService'})]})
)], extraProviders),
ListWrapper.concat([NeedsService], extraProviders)
);
@ -622,7 +622,7 @@ export function main() {
it("should instantiate directives that depend on imperatively created injector providers (bootstrap)", () => {
var imperativelyCreatedInjector = Injector.resolveAndCreate([
provide("service", {asValue: 'appService'})
provide("service", {useValue: 'appService'})
]);
var inj = injector([NeedsService], imperativelyCreatedInjector);
expect(inj.get(NeedsService).service).toEqual('appService');
@ -632,7 +632,7 @@ export function main() {
it("should instantiate directives that depend on imperatively created injector providers (root injector)", () => {
var imperativelyCreatedInjector = Injector.resolveAndCreate([
provide("service", {asValue: 'appService'})
provide("service", {useValue: 'appService'})
]);
var inj = hostShadowInjectors([SimpleDirective], [NeedsService, NeedsServiceFromHost], imperativelyCreatedInjector);
expect(inj.get(NeedsService).service).toEqual('appService');
@ -641,7 +641,7 @@ export function main() {
it("should instantiate directives that depend on imperatively created injector providers (child injector)", () => {
var imperativelyCreatedInjector = Injector.resolveAndCreate([
provide("service", {asValue: 'appService'})
provide("service", {useValue: 'appService'})
]);
var inj = parentChildInjectors([], [NeedsService, NeedsServiceFromHost], null, imperativelyCreatedInjector);
expect(inj.get(NeedsService).service).toEqual('appService');
@ -651,17 +651,17 @@ export function main() {
it("should prioritize viewProviders over providers for the same provider", () => {
var inj = injector(
ListWrapper.concat([DirectiveProvider.createFromType(NeedsService, new ComponentMetadata({
providers: [provide('service', {asValue: 'hostService'})],
viewProviders: [provide('service', {asValue: 'viewService'})]})
providers: [provide('service', {useValue: 'hostService'})],
viewProviders: [provide('service', {useValue: 'viewService'})]})
)], extraProviders), null, true);
expect(inj.get(NeedsService).service).toEqual('viewService');
});
it("should prioritize directive providers over component providers", () => {
var component = DirectiveProvider.createFromType(NeedsService, new ComponentMetadata({
providers: [provide('service', {asValue: 'compService'})]}));
providers: [provide('service', {useValue: 'compService'})]}));
var directive = DirectiveProvider.createFromType(SomeOtherDirective, new DirectiveMetadata({
providers: [provide('service', {asValue: 'dirService'})]}));
providers: [provide('service', {useValue: 'dirService'})]}));
var inj = injector(ListWrapper.concat([component, directive], extraProviders), null, true);
expect(inj.get(NeedsService).service).toEqual('dirService');
});
@ -672,7 +672,7 @@ export function main() {
hostShadowInjectors(
ListWrapper.concat([
DirectiveProvider.createFromType(SomeOtherDirective, new DirectiveMetadata({
providers: [provide('service', {asValue: 'hostService'})]})
providers: [provide('service', {useValue: 'hostService'})]})
)], extraProviders),
ListWrapper.concat([NeedsServiceFromHost], extraProviders)
);
@ -686,7 +686,7 @@ export function main() {
ListWrapper.concat([
SimpleDirective,
DirectiveProvider.createFromType(SomeOtherDirective, new DirectiveMetadata({
providers: [provide('service', {asValue: 'hostService'})]})
providers: [provide('service', {useValue: 'hostService'})]})
)], extraProviders),
ListWrapper.concat([NeedsServiceFromHost], extraProviders)
@ -737,13 +737,13 @@ export function main() {
it("should accept providers instead of types", () => {
var inj = injector(
ListWrapper.concat([provide(SimpleDirective, {asClass: SimpleDirective})], extraProviders));
ListWrapper.concat([provide(SimpleDirective, {useClass: SimpleDirective})], extraProviders));
expect(inj.get(SimpleDirective)).toBeAnInstanceOf(SimpleDirective);
});
it("should allow for direct access using getDirectiveAtIndex", () => {
var providers =
ListWrapper.concat([provide(SimpleDirective, {asClass: SimpleDirective})], extraProviders);
ListWrapper.concat([provide(SimpleDirective, {useClass: SimpleDirective})], extraProviders);
var inj = injector(providers);

View File

@ -97,7 +97,7 @@ const ANCHOR_ELEMENT = CONST_EXPR(new OpaqueToken('AnchorElement'));
export function main() {
describe('integration tests', function() {
beforeEachBindings(() => [provide(ANCHOR_ELEMENT, {asValue: el('<div></div>')})]);
beforeEachBindings(() => [provide(ANCHOR_ELEMENT, {useValue: el('<div></div>')})]);
describe('react to record changes', function() {
it('should consume text node changes',
@ -1517,7 +1517,7 @@ export function main() {
describe('logging property updates', () => {
beforeEachBindings(() => [
provide(ChangeDetectorGenConfig,
{asValue: new ChangeDetectorGenConfig(true, true, true, false)})
{useValue: new ChangeDetectorGenConfig(true, true, true, false)})
]);
it('should reflect property values as attributes',
@ -1741,7 +1741,7 @@ class DynamicViewport {
var myService = new MyService();
myService.greeting = 'dynamic greet';
var bindings = Injector.resolve([provide(MyService, {asValue: myService})]);
var bindings = Injector.resolve([provide(MyService, {useValue: myService})]);
this.done = compiler.compileInHost(ChildCompUsingService)
.then((hostPv) => {vc.createHostView(hostPv, 0, bindings)});
}
@ -2026,7 +2026,7 @@ class PublicApi {
@Directive({
selector: '[public-api]',
providers: [new Provider(PublicApi, {toAlias: PrivateImpl, deps: []})]
providers: [new Provider(PublicApi, {useExisting: PrivateImpl, deps: []})]
})
@Injectable()
class PrivateImpl extends PublicApi {
@ -2094,7 +2094,7 @@ function createInjectableWithLogging(inj: Injector) {
@Component({
selector: 'component-providing-logging-injectable',
providers: [
new Provider(InjectableService, {toFactory: createInjectableWithLogging, deps: [Injector]})
new Provider(InjectableService, {useFactory: createInjectableWithLogging, deps: [Injector]})
]
})
@View({template: ''})
@ -2117,8 +2117,8 @@ class DirectiveProvidingInjectableInView {
@Component({
selector: 'directive-providing-injectable',
providers: [new Provider(InjectableService, {toValue: 'host'})],
viewProviders: [new Provider(InjectableService, {toValue: 'view'})]
providers: [new Provider(InjectableService, {useValue: 'host'})],
viewProviders: [new Provider(InjectableService, {useValue: 'view'})]
})
@View({template: ''})
@Injectable()
@ -2170,7 +2170,7 @@ class EventBus {
@Directive({
selector: 'grand-parent-providing-event-bus',
providers: [new Provider(EventBus, {toValue: new EventBus(null, "grandparent")})]
providers: [new Provider(EventBus, {useValue: new EventBus(null, "grandparent")})]
})
class GrandParentProvidingEventBus {
bus: EventBus;
@ -2186,7 +2186,7 @@ function createParentBus(peb) {
selector: 'parent-providing-event-bus',
providers: [
new Provider(EventBus,
{toFactory: createParentBus, deps: [[EventBus, new SkipSelfMetadata()]]})
{useFactory: createParentBus, deps: [[EventBus, new SkipSelfMetadata()]]})
]
})
@View({

View File

@ -40,7 +40,7 @@ import {By} from 'angular2/src/core/debug';
export function main() {
describe('projection', () => {
beforeEachBindings(() => [provide(AppViewListener, {asClass: AppViewListener})]);
beforeEachBindings(() => [provide(AppViewListener, {useClass: AppViewListener})]);
it('should support simple components',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {

View File

@ -30,8 +30,9 @@ export function main() {
describe("Pipes", () => {
var injector;
beforeEach(
() => { injector = Injector.resolveAndCreate([provide('dep', {asValue: 'dependency'})]); });
beforeEach(() => {
injector = Injector.resolveAndCreate([provide('dep', {useValue: 'dependency'})]);
});
it('should instantiate a pipe', () => {
var proto =

View File

@ -72,9 +72,9 @@ export function main() {
beforeEach(() => {
let injector = Injector.resolveAndCreate([
provide(ResponseOptions, {asClass: BaseResponseOptions}),
provide(BrowserJsonp, {asClass: MockBrowserJsonp}),
provide(JSONPBackend, {asClass: JSONPBackend_})
provide(ResponseOptions, {useClass: BaseResponseOptions}),
provide(BrowserJsonp, {useClass: MockBrowserJsonp}),
provide(JSONPBackend, {useClass: JSONPBackend_})
]);
backend = injector.get(JSONPBackend);
let base = new BaseRequestOptions();

View File

@ -35,7 +35,7 @@ export function main() {
beforeEach(() => {
var injector = Injector.resolveAndCreate(
[provide(ResponseOptions, {asClass: BaseResponseOptions}), MockBackend]);
[provide(ResponseOptions, {useClass: BaseResponseOptions}), MockBackend]);
backend = injector.get(MockBackend);
var base = new BaseRequestOptions();
sampleRequest1 = new Request(base.merge(new RequestOptions({url: 'https://google.com'})));

View File

@ -75,8 +75,8 @@ export function main() {
beforeEach(() => {
var injector = Injector.resolveAndCreate([
provide(ResponseOptions, {asClass: BaseResponseOptions}),
provide(BrowserXhr, {asClass: MockBrowserXHR}),
provide(ResponseOptions, {useClass: BaseResponseOptions}),
provide(BrowserXhr, {useClass: MockBrowserXHR}),
XHRBackend
]);
backend = injector.get(XHRBackend);

View File

@ -59,15 +59,15 @@ export function main() {
it('should allow using jsonpInjectables and httpInjectables in same injector',
inject([AsyncTestCompleter], (async) => {
parentInjector = Injector.resolveAndCreate([
provide(XHRBackend, {asClass: MockBackend}),
provide(JSONPBackend, {asClass: MockBackend})
provide(XHRBackend, {useClass: MockBackend}),
provide(JSONPBackend, {useClass: MockBackend})
]);
childInjector = parentInjector.resolveAndCreateChild([
HTTP_PROVIDERS,
JSONP_PROVIDERS,
provide(XHRBackend, {asClass: MockBackend}),
provide(JSONPBackend, {asClass: MockBackend})
provide(XHRBackend, {useClass: MockBackend}),
provide(JSONPBackend, {useClass: MockBackend})
]);
http = childInjector.get(Http);
@ -115,7 +115,7 @@ export function main() {
provide(
Http,
{
asFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
return new Http(backend, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]
@ -123,7 +123,7 @@ export function main() {
provide(
Jsonp,
{
asFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
return new Jsonp(backend, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]

View File

@ -109,18 +109,22 @@ var NG_API = [
'Binding',
'Binding.dependencies',
'Binding.multi',
'Binding.useExisting',
'Binding.useClass',
'Binding.useFactory',
'Binding.useValue',
'Binding.token',
'Binding.toAlias',
'Binding.toClass',
'Binding.toFactory',
'Binding.toValue',
'Binding.token',
'Provider',
'Provider.dependencies',
'Provider.multi',
'Provider.toAlias',
'Provider.toClass',
'Provider.toFactory',
'Provider.toValue',
'Provider.useExisting',
'Provider.useClass',
'Provider.useFactory',
'Provider.useValue',
'Provider.token',
'ProviderBuilder',
'ProviderBuilder.toAlias()',

View File

@ -64,10 +64,10 @@ export function main() {
beforeEachBindings(() => [
RouteRegistry,
DirectiveResolver,
provide(Location, {asClass: SpyLocation}),
provide(Location, {useClass: SpyLocation}),
provide(Router,
{
asFactory:
useFactory:
(registry, location) => { return new RootRouter(registry, location, MyComp); },
deps: [RouteRegistry, Location]
})

View File

@ -48,10 +48,10 @@ export function main() {
beforeEachBindings(() => [
RouteRegistry,
DirectiveResolver,
provide(Location, {asClass: SpyLocation}),
provide(Location, {useClass: SpyLocation}),
provide(Router,
{
asFactory:
useFactory:
(registry, location) => { return new RootRouter(registry, location, MyComp); },
deps: [RouteRegistry, Location]
})

View File

@ -38,7 +38,7 @@ import {MockLocationStrategy} from 'angular2/src/mock/mock_location_strategy';
export function main() {
describe('router injectables', () => {
beforeEachBindings(() => {
return [ROUTER_PROVIDERS, provide(LocationStrategy, {asClass: MockLocationStrategy})];
return [ROUTER_PROVIDERS, provide(LocationStrategy, {useClass: MockLocationStrategy})];
});
// do not refactor out the `bootstrap` functionality. We still want to
@ -52,9 +52,9 @@ export function main() {
bootstrap(AppCmp,
[
ROUTER_PROVIDERS,
provide(ROUTER_PRIMARY_COMPONENT, {asValue: AppCmp}),
provide(LocationStrategy, {asClass: MockLocationStrategy}),
provide(DOCUMENT, {asValue: fakeDoc})
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppCmp}),
provide(LocationStrategy, {useClass: MockLocationStrategy}),
provide(DOCUMENT, {useValue: fakeDoc})
])
.then((applicationRef) => {
var router = applicationRef.hostComponent.router;
@ -69,7 +69,7 @@ export function main() {
describe('broken app', () => {
beforeEachBindings(
() => { return [provide(ROUTER_PRIMARY_COMPONENT, {asValue: BrokenAppCmp})]; });
() => { return [provide(ROUTER_PRIMARY_COMPONENT, {useValue: BrokenAppCmp})]; });
it('should rethrow exceptions from component constructors',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
@ -86,7 +86,7 @@ export function main() {
describe('back button app', () => {
beforeEachBindings(
() => { return [provide(ROUTER_PRIMARY_COMPONENT, {asValue: HierarchyAppCmp})]; });
() => { return [provide(ROUTER_PRIMARY_COMPONENT, {useValue: HierarchyAppCmp})]; });
it('should change the url without pushing a new history state for back navigations',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
@ -138,7 +138,7 @@ export function main() {
describe('hierarchical app', () => {
beforeEachBindings(
() => { return [provide(ROUTER_PRIMARY_COMPONENT, {asValue: HierarchyAppCmp})]; });
() => { return [provide(ROUTER_PRIMARY_COMPONENT, {useValue: HierarchyAppCmp})]; });
it('should bootstrap an app with a hierarchy',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {
@ -158,7 +158,7 @@ export function main() {
}));
describe('custom app base ref', () => {
beforeEachBindings(() => { return [provide(APP_BASE_HREF, {asValue: '/my/app'})]; });
beforeEachBindings(() => { return [provide(APP_BASE_HREF, {useValue: '/my/app'})]; });
it('should bootstrap',
inject([AsyncTestCompleter, TestComponentBuilder],
(async, tcb: TestComponentBuilder) => {
@ -182,7 +182,7 @@ export function main() {
describe('querystring params app', () => {
beforeEachBindings(
() => { return [provide(ROUTER_PRIMARY_COMPONENT, {asValue: QueryStringAppCmp})]; });
() => { return [provide(ROUTER_PRIMARY_COMPONENT, {useValue: QueryStringAppCmp})]; });
it('should recognize and return querystring params with the injected RouteParams',
inject([AsyncTestCompleter, TestComponentBuilder], (async, tcb: TestComponentBuilder) => {

View File

@ -48,10 +48,10 @@ export function main() {
beforeEachBindings(() => [
RouteRegistry,
DirectiveResolver,
provide(Location, {asClass: SpyLocation}),
provide(Location, {useClass: SpyLocation}),
provide(Router,
{
asFactory:
useFactory:
(registry, location) => { return new RootRouter(registry, location, MyComp); },
deps: [RouteRegistry, Location]
})

View File

@ -27,7 +27,7 @@ export function main() {
locationStrategy = new MockLocationStrategy();
locationStrategy.internalBaseHref = baseHref;
let injector = Injector.resolveAndCreate(
[Location, provide(LocationStrategy, {asValue: locationStrategy}), provider]);
[Location, provide(LocationStrategy, {useValue: locationStrategy}), provider]);
return location = injector.get(Location);
}
@ -71,7 +71,7 @@ export function main() {
});
it('should use optional base href param', () => {
let location = makeLocation('/', provide(APP_BASE_HREF, {asValue: '/my/custom/href'}));
let location = makeLocation('/', provide(APP_BASE_HREF, {useValue: '/my/custom/href'}));
location.go('user/btford');
expect(locationStrategy.path()).toEqual('/my/custom/href/user/btford');
});

View File

@ -49,9 +49,9 @@ export function main() {
var exceptionHandler = new ExceptionHandler(logger, true);
testBindings = [
ROUTER_PROVIDERS,
provide(LocationStrategy, {asClass: MockLocationStrategy}),
provide(DOCUMENT, {asValue: fakeDoc}),
provide(ExceptionHandler, {asValue: exceptionHandler})
provide(LocationStrategy, {useClass: MockLocationStrategy}),
provide(DOCUMENT, {useValue: fakeDoc}),
provide(ExceptionHandler, {useValue: exceptionHandler})
];
});

View File

@ -41,8 +41,8 @@ export function main() {
var tcb: TestComponentBuilder;
beforeEachBindings(() => [
provide(Location, {asValue: makeDummyLocation()}),
provide(Router, {asValue: makeDummyRouter()})
provide(Location, {useValue: makeDummyLocation()}),
provide(Router, {useValue: makeDummyRouter()})
]);
beforeEach(inject([TestComponentBuilder], (tcBuilder) => { tcb = tcBuilder; }));

View File

@ -33,10 +33,10 @@ export function main() {
beforeEachBindings(() => [
RouteRegistry,
DirectiveResolver,
provide(Location, {asClass: SpyLocation}),
provide(Location, {useClass: SpyLocation}),
provide(Router,
{
asFactory:
useFactory:
(registry, location) => { return new RootRouter(registry, location, AppCmp); },
deps: [RouteRegistry, Location]
})

View File

@ -178,7 +178,7 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideProviders(TestBindingsComp,
[provide(FancyService, {asClass: MockFancyService})])
[provide(FancyService, {useClass: MockFancyService})])
.createAsync(TestBindingsComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();
@ -193,7 +193,7 @@ export function main() {
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideViewProviders(TestViewBindingsComp,
[provide(FancyService, {asClass: MockFancyService})])
[provide(FancyService, {useClass: MockFancyService})])
.createAsync(TestViewBindingsComp)
.then((rootTestComponent) => {
rootTestComponent.detectChanges();

View File

@ -7,7 +7,7 @@ export class SpyComponentRef extends SpyObject {
injector;
constructor() {
super();
this.injector = Injector.resolveAndCreate([provide(LifeCycle, {asValue: {tick: () => {}}})]);
this.injector = Injector.resolveAndCreate([provide(LifeCycle, {useValue: {tick: () => {}}})]);
}
}

View File

@ -33,7 +33,7 @@ export function main() {
const ID = "methodId";
beforeEachBindings(() => [
provide(ON_WEB_WORKER, {asValue: true}),
provide(ON_WEB_WORKER, {useValue: true}),
RenderProtoViewRefStore,
RenderViewWithFragmentsStore
]);

View File

@ -27,7 +27,7 @@ import {EVENT_CHANNEL} from 'angular2/src/web_workers/shared/messaging_api';
export function main() {
describe("EventDispatcher", () => {
beforeEachBindings(() => [
provide(ON_WEB_WORKER, {asValue: true}),
provide(ON_WEB_WORKER, {useValue: true}),
RenderProtoViewRefStore,
RenderViewWithFragmentsStore
]);

View File

@ -104,21 +104,21 @@ export function main() {
var uiRenderProtoViewStore = new RenderProtoViewRefStore(false);
uiRenderViewStore = new RenderViewWithFragmentsStore(false);
uiInjector = createTestInjector([
provide(RenderProtoViewRefStore, {asValue: uiRenderProtoViewStore}),
provide(RenderViewWithFragmentsStore, {asValue: uiRenderViewStore}),
provide(DomRenderer, {asClass: DomRenderer_}),
provide(Renderer, {asAlias: DomRenderer})
provide(RenderProtoViewRefStore, {useValue: uiRenderProtoViewStore}),
provide(RenderViewWithFragmentsStore, {useValue: uiRenderViewStore}),
provide(DomRenderer, {useClass: DomRenderer_}),
provide(Renderer, {useExisting: DomRenderer})
]);
var uiSerializer = uiInjector.get(Serializer);
var domRenderer = uiInjector.get(DomRenderer);
var workerRenderProtoViewStore = new RenderProtoViewRefStore(true);
var workerRenderViewStore = new RenderViewWithFragmentsStore(true);
return [
provide(RenderProtoViewRefStore, {asValue: workerRenderProtoViewStore}),
provide(RenderViewWithFragmentsStore, {asValue: workerRenderViewStore}),
provide(RenderProtoViewRefStore, {useValue: workerRenderProtoViewStore}),
provide(RenderViewWithFragmentsStore, {useValue: workerRenderViewStore}),
provide(Renderer,
{
asFactory: (workerSerializer) => {
useFactory: (workerSerializer) => {
return createWorkerRenderer(workerSerializer, uiSerializer, domRenderer,
uiRenderProtoViewStore, uiRenderViewStore,
workerRenderProtoViewStore, workerRenderViewStore);

View File

@ -55,7 +55,7 @@ export class MdDialog {
// Create the dialogRef here so that it can be injected into the content component.
var dialogRef = new MdDialogRef();
var bindings = Injector.resolve([provide(MdDialogRef, {asValue: dialogRef})]);
var bindings = Injector.resolve([provide(MdDialogRef, {useValue: dialogRef})]);
var backdropRefPromise = this._openBackdrop(elementRef, bindings);

View File

@ -37,7 +37,7 @@ export function main() {
// Need to use the real XHR implementation (instead of the mock) so we can actually request
// the template files, since Angular 2 doesn't have anything like $templateCache. This should
// eventually be replaced with a preprocessor that inlines templates.
provide(XHR, {asClass: XHRImpl})
provide(XHR, {useClass: XHRImpl})
]);
beforeEach(inject([TestComponentBuilder], (tcb) => { builder = tcb; }));

View File

@ -28,7 +28,7 @@ function _createBindings(): Provider[] {
return [
provide(ViewResolver,
{
asFactory: () => new MultiplyViewResolver(
useFactory: () => new MultiplyViewResolver(
multiplyTemplatesBy,
[BenchmarkComponentNoBindings, BenchmarkComponentWithBindings]),
deps: []
@ -36,7 +36,7 @@ function _createBindings(): Provider[] {
// Use DynamicChangeDetector as that is the only one that Dart supports as well
// so that we can compare the numbers between JS and Dart
provide(ChangeDetectorGenConfig,
{asValue: new ChangeDetectorGenConfig(false, false, false, false)})
{useValue: new ChangeDetectorGenConfig(false, false, false, false)})
];
}

View File

@ -27,7 +27,7 @@ export function main() {
.resolveAndCreateChild([])
.resolveAndCreateChild([]);
var variousProviders = [A, provide(B, {asClass: C}), [D, [E]], provide(F, {asValue: 6})];
var variousProviders = [A, provide(B, {useClass: C}), [D, [E]], provide(F, {useValue: 6})];
var variousProvidersResolved = Injector.resolve(variousProviders);

View File

@ -35,11 +35,10 @@ export const LARGETABLE_COLS = 'LargetableComponent.cols';
function _createBindings() {
var viewCacheCapacity = getStringParameter('viewcache') == 'true' ? 10000 : 1;
return [
bind(BENCHMARK_TYPE)
.toValue(getStringParameter('benchmarkType')),
provide(LARGETABLE_ROWS, {asValue: getIntParameter('rows')}),
provide(LARGETABLE_COLS, {asValue: getIntParameter('columns')}),
provide(APP_VIEW_POOL_CAPACITY, {asValue: viewCacheCapacity})
provide(BENCHMARK_TYPE, {useValue: getStringParameter('benchmarkType')}),
provide(LARGETABLE_ROWS, {useValue: getIntParameter('rows')}),
provide(LARGETABLE_COLS, {useValue: getIntParameter('columns')}),
provide(APP_VIEW_POOL_CAPACITY, {useValue: viewCacheCapacity})
];
}

View File

@ -10,5 +10,5 @@ export function main() {
}
function createBindings(): any[] {
return [provide(APP_VIEW_POOL_CAPACITY, {asValue: 100000})];
return [provide(APP_VIEW_POOL_CAPACITY, {useValue: 100000})];
}

View File

@ -28,7 +28,7 @@ import {APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/linker/view_pool';
function createBindings(): Provider[] {
var viewCacheCapacity = getStringParameter('viewcache') == 'true' ? 10000 : 0;
return [provide(APP_VIEW_POOL_CAPACITY, {asValue: viewCacheCapacity})];
return [provide(APP_VIEW_POOL_CAPACITY, {useValue: viewCacheCapacity})];
}
function setupReflector() {

View File

@ -27,7 +27,7 @@ import {APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/linker/view_pool';
function createProviders(): Provider[] {
var viewCacheCapacity = getStringParameter('viewcache') == 'true' ? 10000 : 1;
return [provide(APP_VIEW_POOL_CAPACITY, {asValue: viewCacheCapacity})];
return [provide(APP_VIEW_POOL_CAPACITY, {useValue: viewCacheCapacity})];
}
var BASELINE_TREE_TEMPLATE;

View File

@ -45,10 +45,10 @@ var _CAPTURE_FRAMES = new OpaqueToken('Options.frameCapture');
var _DEFAULT_PROVIDERS = [
bind(_DEFAULT_DESCRIPTION)
.toValue({}),
provide(_SAMPLE_DESCRIPTION, {asValue: {}}),
provide(_FORCE_GC, {asValue: false}),
provide(_PREPARE, {asValue: false}),
provide(_MICRO_METRICS, {asValue: {}}),
provide(_NOW, {asValue: () => DateWrapper.now()}),
provide(_CAPTURE_FRAMES, {asValue: false})
provide(_SAMPLE_DESCRIPTION, {useValue: {}}),
provide(_FORCE_GC, {useValue: false}),
provide(_PREPARE, {useValue: false}),
provide(_MICRO_METRICS, {useValue: {}}),
provide(_NOW, {useValue: () => DateWrapper.now()}),
provide(_CAPTURE_FRAMES, {useValue: false})
];

View File

@ -1,11 +1,11 @@
import {bind, provide, Binding, Injector, OpaqueToken} from 'angular2/src/core/di';
import {bind, provide, Binding, Provider, Injector, OpaqueToken} from 'angular2/src/core/di';
import {StringMapWrapper} from 'angular2/src/core/facade/collection';
import {Promise, PromiseWrapper} from 'angular2/src/core/facade/async';
import {Metric} from '../metric';
export class MultiMetric extends Metric {
static createBindings(childTokens: any[]): Binding[] {
static createBindings(childTokens: any[]): Provider[] {
return [
bind(_CHILDREN)
.toFactory((injector: Injector) => childTokens.map(token => injector.get(token)),

View File

@ -343,5 +343,5 @@ var _PROVIDERS = [
Options.FORCE_GC,
Options.CAPTURE_FRAMES
]),
provide(_SET_TIMEOUT, {asValue: (fn, millis) => TimerWrapper.setTimeout(fn, millis)})
provide(_SET_TIMEOUT, {useValue: (fn, millis) => TimerWrapper.setTimeout(fn, millis)})
];

View File

@ -98,6 +98,6 @@ var _PROVIDERS = [
.toFactory((columnWidth, sampleDescription, print) =>
new ConsoleReporter(columnWidth, sampleDescription, print),
[_COLUMN_WIDTH, SampleDescription, _PRINT]),
provide(_COLUMN_WIDTH, {asValue: 18}),
provide(_PRINT, {asValue: print})
provide(_COLUMN_WIDTH, {useValue: 18}),
provide(_PRINT, {useValue: print})
];

View File

@ -52,5 +52,5 @@ var _PROVIDERS = [
.toFactory((sampleDescription, path, writeFile, now) =>
new JsonFileReporter(sampleDescription, path, writeFile, now),
[SampleDescription, _PATH, Options.WRITE_FILE, Options.NOW]),
provide(_PATH, {asValue: '.'})
provide(_PATH, {useValue: '.'})
];

View File

@ -68,7 +68,7 @@ export class Runner {
sampleBindings,
bind(Options.CAPABILITIES).toValue(capabilities),
bind(Options.USER_AGENT).toValue(userAgent),
provide(WebDriverAdapter, {asValue: adapter})
provide(WebDriverAdapter, {useValue: adapter})
]);
var sampler = injector.get(Sampler);

View File

@ -57,6 +57,6 @@ var _PROVIDERS = [
bind(RegressionSlopeValidator)
.toFactory((sampleSize, metric) => new RegressionSlopeValidator(sampleSize, metric),
[_SAMPLE_SIZE, _METRIC]),
provide(_SAMPLE_SIZE, {asValue: 10}),
provide(_METRIC, {asValue: 'scriptTime'})
provide(_SAMPLE_SIZE, {useValue: 10}),
provide(_METRIC, {useValue: 'scriptTime'})
];

View File

@ -36,5 +36,5 @@ var _SAMPLE_SIZE = new OpaqueToken('SizeValidator.sampleSize');
var _PROVIDERS = [
bind(SizeValidator)
.toFactory((size) => new SizeValidator(size), [_SAMPLE_SIZE]),
provide(_SAMPLE_SIZE, {asValue: 10})
provide(_SAMPLE_SIZE, {useValue: 10})
];

View File

@ -19,7 +19,7 @@ import {Metric, MultiMetric, bind, provide, Injector} from 'benchpress/common';
export function main() {
function createMetric(ids: any[]) {
var m = Injector.resolveAndCreate([
ids.map(id => provide(id, {asValue: new MockMetric(id)})),
ids.map(id => provide(id, {useValue: new MockMetric(id)})),
MultiMetric.createBindings(ids)
])
.get(MultiMetric);

View File

@ -30,7 +30,7 @@ export function main() {
var bindings = [
ConsoleReporter.BINDINGS,
provide(SampleDescription,
{asValue: new SampleDescription(sampleId, descriptions, metrics)}),
{useValue: new SampleDescription(sampleId, descriptions, metrics)}),
bind(ConsoleReporter.PRINT).toValue((line) => log.push(line))
];
if (isPresent(columnWidth)) {

View File

@ -34,7 +34,7 @@ export function main() {
var bindings = [
JsonFileReporter.BINDINGS,
provide(SampleDescription,
{asValue: new SampleDescription(sampleId, descriptions, metrics)}),
{useValue: new SampleDescription(sampleId, descriptions, metrics)}),
bind(JsonFileReporter.PATH).toValue(path),
bind(Options.NOW).toValue(() => DateWrapper.fromMillis(1234)),
bind(Options.WRITE_FILE)

View File

@ -19,7 +19,7 @@ import {Reporter, MultiReporter, bind, provide, Injector, MeasureValues} from 'b
export function main() {
function createReporters(ids: any[]) {
var r = Injector.resolveAndCreate([
ids.map(id => provide(id, {asValue: new MockReporter(id)})),
ids.map(id => provide(id, {useValue: new MockReporter(id)})),
MultiReporter.createBindings(ids)
])
.get(MultiReporter);

View File

@ -54,11 +54,11 @@ export function main() {
var bindings = [
Options.DEFAULT_PROVIDERS,
Sampler.BINDINGS,
provide(Metric, {asValue: metric}),
provide(Reporter, {asValue: reporter}),
provide(WebDriverAdapter, {asValue: driver}),
provide(Metric, {useValue: metric}),
provide(Reporter, {useValue: reporter}),
provide(WebDriverAdapter, {useValue: driver}),
bind(Options.EXECUTE).toValue(execute),
provide(Validator, {asValue: validator}),
provide(Validator, {useValue: validator}),
bind(Options.NOW).toValue(() => DateWrapper.fromMillis(time++))
];
if (isPresent(prepare)) {

View File

@ -20,7 +20,7 @@ export function main() {
function createExtension(ids: any[], caps) {
return PromiseWrapper.wrap(() => {
return Injector.resolveAndCreate([
ids.map(id => provide(id, {asValue: new MockExtension(id)})),
ids.map(id => provide(id, {useValue: new MockExtension(id)})),
bind(Options.CAPABILITIES).toValue(caps),
WebDriverExtension.bindTo(ids)
])

View File

@ -40,7 +40,7 @@ export function main() {
extension =
Injector.resolveAndCreate([
IOsDriverExtension.BINDINGS,
provide(WebDriverAdapter, {asValue: new MockDriverAdapter(log, perfRecords)})
provide(WebDriverAdapter, {useValue: new MockDriverAdapter(log, perfRecords)})
])
.get(IOsDriverExtension);
return extension;

View File

@ -40,5 +40,5 @@ class DemoApp {
export function main() {
commonDemoSetup();
bootstrap(DemoApp, [provide(UrlResolver, {asValue: new DemoUrlResolver()})]);
bootstrap(DemoApp, [provide(UrlResolver, {useValue: new DemoUrlResolver()})]);
}

View File

@ -34,5 +34,5 @@ class DemoApp {
export function main() {
commonDemoSetup();
bootstrap(DemoApp, [provide(UrlResolver, {asValue: new DemoUrlResolver()})]);
bootstrap(DemoApp, [provide(UrlResolver, {useValue: new DemoUrlResolver()})]);
}

Some files were not shown because too many files have changed in this diff Show More