Skip to content

Commit 1eb0162

Browse files
committed
feat(di): rename Binding into Provider
Closes angular#4416 Closes angular#4654
1 parent 7c6130c commit 1eb0162

File tree

190 files changed

+2073
-1818
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+2073
-1818
lines changed

docs/typescript-definition-package/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
7272
{
7373
id: 'angular2/test_lib',
7474
references: ['./angular2.d.ts'],
75-
remapTypes: { Type: 'ng.Type', Binding: 'ng.Binding', ViewMetadata: 'ng.ViewMetadata', Injector: 'ng.Injector',
75+
remapTypes: { Type: 'ng.Type', Binding: 'ng.Binding', Provider: 'ng.Provider', ViewMetadata: 'ng.ViewMetadata', Injector: 'ng.Injector',
7676
Predicate: 'ng.Predicate', ElementRef: 'ng.ElementRef', DebugElement: 'ng.DebugElement',
7777
InjectableReference: 'ng.InjectableReference', ComponentRef: 'ng.ComponentRef' },
7878
modules: {'angular2/test_lib': {namespace: 'ngTestLib', id: 'angular2/test_lib'}}

modules/angular2/angular2.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ library angular2;
88
export 'package:angular2/core.dart' hide forwardRef, resolveForwardRef, ForwardRefFn;
99
export 'package:angular2/profile.dart';
1010
export 'package:angular2/lifecycle_hooks.dart';
11-
export 'package:angular2/src/core/application_tokens.dart' hide APP_COMPONENT_REF_PROMISE, APP_ID_RANDOM_BINDING;
11+
export 'package:angular2/src/core/application_tokens.dart' hide APP_COMPONENT_REF_PROMISE, APP_ID_RANDOM_PROVIDER;
1212
export 'package:angular2/src/core/render/dom/dom_tokens.dart';

modules/angular2/docs/di/di.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ while (inj) {
108108
inj = inj.parent;
109109
}
110110
}
111-
throw new NoBindingError(requestedKey);
111+
throw new NoProviderError(requestedKey);
112112
```
113113

114114
So in the following example
@@ -160,7 +160,7 @@ var child = parent.resolveAndCreateChild([
160160
bind(Engine).toClass(TurboEngine)
161161
]);
162162
163-
parent.get(Car); // will throw NoBindingError
163+
parent.get(Car); // will throw NoProviderError
164164
```
165165

166166

modules/angular2/http.ts

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* The http module provides services to perform http requests. To get started, see the {@link Http}
55
* class.
66
*/
7-
import {bind, Binding} from 'angular2/core';
7+
import {provide, Provider} from 'angular2/core';
88
import {Http, Jsonp} from './src/http/http';
99
import {XHRBackend, XHRConnection} from './src/http/backends/xhr_backend';
1010
import {JSONPBackend, JSONPBackend_, JSONPConnection} from './src/http/backends/jsonp_backend';
@@ -40,18 +40,18 @@ export {URLSearchParams} from './src/http/url_search_params';
4040
/**
4141
* Provides a basic set of injectables to use the {@link Http} service in any application.
4242
*
43-
* The `HTTP_BINDINGS` should be included either in a component's injector,
43+
* The `HTTP_PROVIDERS` should be included either in a component's injector,
4444
* or in the root injector when bootstrapping an application.
4545
*
4646
* ### Example ([live demo](http://plnkr.co/edit/snj7Nv?p=preview))
4747
*
4848
* ```
4949
* import {bootstrap, Component, NgFor, View} from 'angular2/angular2';
50-
* import {HTTP_BINDINGS, Http} from 'angular2/http';
50+
* import {HTTP_PROVIDERS, Http} from 'angular2/http';
5151
*
5252
* @Component({
5353
* selector: 'app',
54-
* bindings: [HTTP_BINDINGS]
54+
* providers: [HTTP_PROVIDERS]
5555
* })
5656
* @View({
5757
* template: `
@@ -83,11 +83,11 @@ export {URLSearchParams} from './src/http/url_search_params';
8383
* .catch(err => console.error(err));
8484
* ```
8585
*
86-
* The primary public API included in `HTTP_BINDINGS` is the {@link Http} class.
87-
* However, other bindings required by `Http` are included,
86+
* The primary public API included in `HTTP_PROVIDERS` is the {@link Http} class.
87+
* However, other providers required by `Http` are included,
8888
* which may be beneficial to override in certain cases.
8989
*
90-
* The bindings included in `HTTP_BINDINGS` include:
90+
* The providers included in `HTTP_PROVIDERS` include:
9191
* * {@link Http}
9292
* * {@link XHRBackend}
9393
* * `BrowserXHR` - Private factory to create `XMLHttpRequest` instances
@@ -96,38 +96,38 @@ export {URLSearchParams} from './src/http/url_search_params';
9696
*
9797
* There may be cases where it makes sense to extend the base request options,
9898
* such as to add a search string to be appended to all URLs.
99-
* To accomplish this, a new binding for {@link RequestOptions} should
100-
* be added in the same injector as `HTTP_BINDINGS`.
99+
* To accomplish this, a new provider for {@link RequestOptions} should
100+
* be added in the same injector as `HTTP_PROVIDERS`.
101101
*
102102
* ### Example ([live demo](http://plnkr.co/edit/aCMEXi?p=preview))
103103
*
104104
* ```
105-
* import {bind, bootstrap} from 'angular2/angular2';
106-
* import {HTTP_BINDINGS, BaseRequestOptions, RequestOptions} from 'angular2/http';
105+
* import {provide, bootstrap} from 'angular2/angular2';
106+
* import {HTTP_PROVIDERS, BaseRequestOptions, RequestOptions} from 'angular2/http';
107107
*
108108
* class MyOptions extends BaseRequestOptions {
109109
* search: string = 'coreTeam=true';
110110
* }
111111
*
112-
* bootstrap(App, [HTTP_BINDINGS, bind(RequestOptions).toClass(MyOptions)])
112+
* bootstrap(App, [HTTP_PROVIDERS, provide(RequestOptions, {asClass: MyOptions})])
113113
* .catch(err => console.error(err));
114114
* ```
115115
*
116116
* Likewise, to use a mock backend for unit tests, the {@link XHRBackend}
117-
* binding should be bound to {@link MockBackend}.
117+
* provider should be bound to {@link MockBackend}.
118118
*
119119
* ### Example ([live demo](http://plnkr.co/edit/7LWALD?p=preview))
120120
*
121121
* ```
122-
* import {bind, Injector} from 'angular2/angular2';
123-
* import {HTTP_BINDINGS, Http, Response, XHRBackend, MockBackend} from 'angular2/http';
122+
* import {provide, Injector} from 'angular2/angular2';
123+
* import {HTTP_PROVIDERS, Http, Response, XHRBackend, MockBackend} from 'angular2/http';
124124
*
125125
* var people = [{name: 'Jeff'}, {name: 'Tobias'}];
126126
*
127127
* var injector = Injector.resolveAndCreate([
128-
* HTTP_BINDINGS,
128+
* HTTP_PROVIDERS,
129129
* MockBackend,
130-
* bind(XHRBackend).toAlias(MockBackend)
130+
* provide(XHRBackend, {asAlias: MockBackend})
131131
* ]);
132132
* var http = injector.get(Http);
133133
* var backend = injector.get(MockBackend);
@@ -150,34 +150,40 @@ export {URLSearchParams} from './src/http/url_search_params';
150150
* });
151151
* ```
152152
*/
153-
export const HTTP_BINDINGS: any[] = [
153+
export const HTTP_PROVIDERS: any[] = [
154154
// TODO(pascal): use factory type annotations once supported in DI
155155
// issue: https://github.com/angular/angular/issues/3183
156-
bind(Http)
157-
.toFactory((xhrBackend, requestOptions) => { return new Http(xhrBackend, requestOptions);},
158-
[XHRBackend, RequestOptions]),
156+
provide(Http,
157+
{
158+
asFactory: (xhrBackend, requestOptions) => new Http(xhrBackend, requestOptions),
159+
deps: [XHRBackend, RequestOptions]
160+
}),
159161
BrowserXhr,
160-
bind(RequestOptions).toClass(BaseRequestOptions),
161-
bind(ResponseOptions).toClass(BaseResponseOptions),
162+
provide(RequestOptions, {asClass: BaseRequestOptions}),
163+
provide(ResponseOptions, {asClass: BaseResponseOptions}),
162164
XHRBackend
163165
];
164166

167+
/**
168+
* @deprecated
169+
*/
170+
export const HTTP_BINDINGS = HTTP_PROVIDERS;
165171

166172
/**
167-
* Provides a basic set of bindings to use the {@link Jsonp} service in any application.
173+
* Provides a basic set of providers to use the {@link Jsonp} service in any application.
168174
*
169-
* The `JSONP_BINDINGS` should be included either in a component's injector,
175+
* The `JSONP_PROVIDERS` should be included either in a component's injector,
170176
* or in the root injector when bootstrapping an application.
171177
*
172178
* ### Example ([live demo](http://plnkr.co/edit/vmeN4F?p=preview))
173179
*
174180
* ```
175181
* import {Component, NgFor, View} from 'angular2/angular2';
176-
* import {JSONP_BINDINGS, Jsonp} from 'angular2/http';
182+
* import {JSONP_PROVIDERS, Jsonp} from 'angular2/http';
177183
*
178184
* @Component({
179185
* selector: 'app',
180-
* bindings: [JSONP_BINDINGS]
186+
* providers: [JSONP_PROVIDERS]
181187
* })
182188
* @View({
183189
* template: `
@@ -202,11 +208,11 @@ export const HTTP_BINDINGS: any[] = [
202208
* }
203209
* ```
204210
*
205-
* The primary public API included in `JSONP_BINDINGS` is the {@link Jsonp} class.
206-
* However, other bindings required by `Jsonp` are included,
211+
* The primary public API included in `JSONP_PROVIDERS` is the {@link Jsonp} class.
212+
* However, other providers required by `Jsonp` are included,
207213
* which may be beneficial to override in certain cases.
208214
*
209-
* The bindings included in `JSONP_BINDINGS` include:
215+
* The providers included in `JSONP_PROVIDERS` include:
210216
* * {@link Jsonp}
211217
* * {@link JSONPBackend}
212218
* * `BrowserJsonp` - Private factory
@@ -215,37 +221,37 @@ export const HTTP_BINDINGS: any[] = [
215221
*
216222
* There may be cases where it makes sense to extend the base request options,
217223
* such as to add a search string to be appended to all URLs.
218-
* To accomplish this, a new binding for {@link RequestOptions} should
219-
* be added in the same injector as `JSONP_BINDINGS`.
224+
* To accomplish this, a new provider for {@link RequestOptions} should
225+
* be added in the same injector as `JSONP_PROVIDERS`.
220226
*
221227
* ### Example ([live demo](http://plnkr.co/edit/TFug7x?p=preview))
222228
*
223229
* ```
224-
* import {bind, bootstrap} from 'angular2/angular2';
225-
* import {JSONP_BINDINGS, BaseRequestOptions, RequestOptions} from 'angular2/http';
230+
* import {provide, bootstrap} from 'angular2/angular2';
231+
* import {JSONP_PROVIDERS, BaseRequestOptions, RequestOptions} from 'angular2/http';
226232
*
227233
* class MyOptions extends BaseRequestOptions {
228234
* search: string = 'coreTeam=true';
229235
* }
230236
*
231-
* bootstrap(App, [JSONP_BINDINGS, bind(RequestOptions).toClass(MyOptions)])
237+
* bootstrap(App, [JSONP_PROVIDERS, provide(RequestOptions, {asClass: MyOptions})])
232238
* .catch(err => console.error(err));
233239
* ```
234240
*
235241
* Likewise, to use a mock backend for unit tests, the {@link JSONPBackend}
236-
* binding should be bound to {@link MockBackend}.
242+
* provider should be bound to {@link MockBackend}.
237243
*
238244
* ### Example ([live demo](http://plnkr.co/edit/HDqZWL?p=preview))
239245
*
240246
* ```
241-
* import {bind, Injector} from 'angular2/angular2';
242-
* import {JSONP_BINDINGS, Jsonp, Response, JSONPBackend, MockBackend} from 'angular2/http';
247+
* import {provide, Injector} from 'angular2/angular2';
248+
* import {JSONP_PROVIDERS, Jsonp, Response, JSONPBackend, MockBackend} from 'angular2/http';
243249
*
244250
* var people = [{name: 'Jeff'}, {name: 'Tobias'}];
245251
* var injector = Injector.resolveAndCreate([
246-
* JSONP_BINDINGS,
252+
* JSONP_PROVIDERS,
247253
* MockBackend,
248-
* bind(JSONPBackend).toAlias(MockBackend)
254+
* provide(JSONPBackend, {asAlias: MockBackend})
249255
* ]);
250256
* var jsonp = injector.get(Jsonp);
251257
* var backend = injector.get(MockBackend);
@@ -268,15 +274,21 @@ export const HTTP_BINDINGS: any[] = [
268274
* });
269275
* ```
270276
*/
271-
export const JSONP_BINDINGS: any[] = [
277+
export const JSONP_PROVIDERS: any[] = [
272278
// TODO(pascal): use factory type annotations once supported in DI
273279
// issue: https://github.com/angular/angular/issues/3183
274-
bind(Jsonp)
275-
.toFactory(
276-
(jsonpBackend, requestOptions) => { return new Jsonp(jsonpBackend, requestOptions);},
277-
[JSONPBackend, RequestOptions]),
280+
provide(Jsonp,
281+
{
282+
asFactory: (jsonpBackend, requestOptions) => new Jsonp(jsonpBackend, requestOptions),
283+
deps: [JSONPBackend, RequestOptions]
284+
}),
278285
BrowserJsonp,
279-
bind(RequestOptions).toClass(BaseRequestOptions),
280-
bind(ResponseOptions).toClass(BaseResponseOptions),
281-
bind(JSONPBackend).toClass(JSONPBackend_)
286+
provide(RequestOptions, {asClass: BaseRequestOptions}),
287+
provide(ResponseOptions, {asClass: BaseResponseOptions}),
288+
provide(JSONPBackend, {asClass: JSONPBackend_})
282289
];
290+
291+
/**
292+
* @deprecated
293+
*/
294+
export const JSON_BINDINGS = JSONP_PROVIDERS;

modules/angular2/router.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {RouterOutlet} from './src/router/router_outlet';
2828
import {RouterLink} from './src/router/router_link';
2929
import {RouteRegistry} from './src/router/route_registry';
3030
import {Location} from './src/router/location';
31-
import {bind, OpaqueToken, Binding} from './core';
31+
import {provide, OpaqueToken, Provider} from './core';
3232
import {CONST_EXPR} from './src/core/facade/lang';
3333
import {ApplicationRef} from './src/core/application_ref';
3434
import {BaseException} from 'angular2/src/core/facade/exceptions';
@@ -44,7 +44,7 @@ import {BaseException} from 'angular2/src/core/facade/exceptions';
4444
* import {Component, View} from 'angular2/angular2';
4545
* import {
4646
* ROUTER_DIRECTIVES,
47-
* ROUTER_BINDINGS,
47+
* ROUTER_PROVIDERS,
4848
* RouteConfig
4949
* } from 'angular2/router';
5050
*
@@ -57,7 +57,7 @@ import {BaseException} from 'angular2/src/core/facade/exceptions';
5757
* // ...
5858
* }
5959
*
60-
* bootstrap(AppCmp, [ROUTER_BINDINGS]);
60+
* bootstrap(AppCmp, [ROUTER_PROVIDERS]);
6161
* ```
6262
*/
6363
export const ROUTER_PRIMARY_COMPONENT: OpaqueToken =
@@ -72,7 +72,7 @@ export const ROUTER_PRIMARY_COMPONENT: OpaqueToken =
7272
*
7373
* ```
7474
* import {Component, View} from 'angular2/angular2';
75-
* import {ROUTER_DIRECTIVES, ROUTER_BINDINGS, RouteConfig} from 'angular2/router';
75+
* import {ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig} from 'angular2/router';
7676
*
7777
* @Component({...})
7878
* @View({directives: [ROUTER_DIRECTIVES]})
@@ -83,21 +83,21 @@ export const ROUTER_PRIMARY_COMPONENT: OpaqueToken =
8383
* // ...
8484
* }
8585
*
86-
* bootstrap(AppCmp, ROUTER_BINDINGS);
86+
* bootstrap(AppCmp, [ROUTER_PROVIDERS]);
8787
* ```
8888
*/
8989
export const ROUTER_DIRECTIVES: any[] = CONST_EXPR([RouterOutlet, RouterLink]);
9090

9191
/**
92-
* A list of {@link Binding}s. To use the router, you must add this to your application.
92+
* A list of {@link Provider}s. To use the router, you must add this to your application.
9393
*
9494
* ## Example ([live demo](http://plnkr.co/edit/iRUP8B5OUbxCWQ3AcIDm))
9595
*
9696
* ```
9797
* import {Component, View} from 'angular2/angular2';
9898
* import {
9999
* ROUTER_DIRECTIVES,
100-
* ROUTER_BINDINGS,
100+
* ROUTER_PROVIDERS,
101101
* RouteConfig
102102
* } from 'angular2/router';
103103
*
@@ -110,23 +110,29 @@ export const ROUTER_DIRECTIVES: any[] = CONST_EXPR([RouterOutlet, RouterLink]);
110110
* // ...
111111
* }
112112
*
113-
* bootstrap(AppCmp, [ROUTER_BINDINGS]);
113+
* bootstrap(AppCmp, [ROUTER_PROVIDERS]);
114114
* ```
115115
*/
116-
export const ROUTER_BINDINGS: any[] = CONST_EXPR([
116+
export const ROUTER_PROVIDERS: any[] = CONST_EXPR([
117117
RouteRegistry,
118-
CONST_EXPR(new Binding(LocationStrategy, {toClass: PathLocationStrategy})),
118+
CONST_EXPR(new Provider(LocationStrategy, {toClass: PathLocationStrategy})),
119119
Location,
120-
CONST_EXPR(new Binding(Router,
121-
{
122-
toFactory: routerFactory,
123-
deps: CONST_EXPR([RouteRegistry, Location, ROUTER_PRIMARY_COMPONENT])
124-
})),
125-
CONST_EXPR(new Binding(
120+
CONST_EXPR(
121+
new Provider(Router,
122+
{
123+
toFactory: routerFactory,
124+
deps: CONST_EXPR([RouteRegistry, Location, ROUTER_PRIMARY_COMPONENT])
125+
})),
126+
CONST_EXPR(new Provider(
126127
ROUTER_PRIMARY_COMPONENT,
127128
{toFactory: routerPrimaryComponentFactory, deps: CONST_EXPR([ApplicationRef])}))
128129
]);
129130

131+
/**
132+
* @deprecated
133+
*/
134+
export const ROUTER_BINDINGS = ROUTER_PROVIDERS;
135+
130136
function routerFactory(registry, location, primaryComponent) {
131137
return new RootRouter(registry, location, primaryComponent);
132138
}

modules/angular2/src/core/application.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export 'package:angular2/src/core/linker/dynamic_component_loader.dart' show Com
1818
///
1919
/// See [commonBootstrap] for detailed documentation.
2020
Future<ComponentRef> bootstrap(Type appComponentType,
21-
[List componentInjectableBindings]) {
21+
[List componentInjectableProviders]) {
2222
reflector.reflectionCapabilities = new ReflectionCapabilities();
23-
var bindings = [compilerBindings()];
24-
if (componentInjectableBindings != null) {
25-
bindings.add(componentInjectableBindings);
23+
var providers = [compilerProviders()];
24+
if (componentInjectableProviders != null) {
25+
providers.add(componentInjectableProviders);
2626
}
27-
return commonBootstrap(appComponentType, bindings);
27+
return commonBootstrap(appComponentType, providers);
2828
}

0 commit comments

Comments
 (0)