Skip to content

Commit f0e962c

Browse files
committed
feat(di): removed app injector
BREAKING CHANGE: THe appInjector property has been removed. Instead use viewInjector or hostInjector.
1 parent 73a939e commit f0e962c

36 files changed

+461
-564
lines changed

modules/angular2/di.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ export {
3636
PUBLIC_AND_PRIVATE,
3737
PUBLIC,
3838
PRIVATE,
39-
undefinedValue,
40-
InjectorInlineStrategy,
41-
InjectorDynamicStrategy
39+
undefinedValue
4240
} from './src/di/injector';
4341
export {Binding, BindingBuilder, ResolvedBinding, Dependency, bind} from './src/di/binding';
4442
export {Key, KeyRegistry, TypeLiteral} from './src/di/key';

modules/angular2/docs/core/02_directives.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ To better understand the kinds of injections which are supported in Angular we h
216216

217217
### Injecting Services
218218

219-
Service injection is the most straight forward kind of injection which Angular supports. It involves a component configuring the `appInjector` and then letting the directive ask for the configured service.
219+
Service injection is the most straight forward kind of injection which Angular supports. It involves a component configuring the `viewInjector` or `hostInjector` and then letting the directive ask for the configured service.
220220

221221
This example illustrates how to inject `MyService` into `House` directive.
222222

@@ -227,7 +227,7 @@ class MyService {} | Assume a service which needs to be inject
227227
|
228228
@Component({ | Assume a top level application component which
229229
selector: 'my-app', | configures the services to be injected.
230-
appInjector: [MyService] |
230+
viewInjector: [MyService] |
231231
}) |
232232
@View({ | Assume we have a template that needs to be
233233
templateUrl: 'my_app.html', | configured with directives to be injected.
@@ -329,8 +329,7 @@ Shadow DOM provides an encapsulation for components, so as a general rule it doe
329329

330330
```
331331
@Component({
332-
selector: '[kid]',
333-
appInjector: []
332+
selector: '[kid]'
334333
})
335334
@View({
336335
templateUrl: 'kid.html',
@@ -348,8 +347,7 @@ class Kid {
348347
}
349348
350349
@Component({
351-
selector: '[dad]',
352-
appInjector: [Grandpa]
350+
selector: '[dad]'
353351
})
354352
@View({
355353
templateUrl: 'dad.html',
@@ -364,7 +362,7 @@ class Dad {
364362
365363
@Component({
366364
selector: '[grandpa]',
367-
appInjector: []
365+
viewInjector: []
368366
})
369367
@View({
370368
templateUrl: 'grandpa.html',

modules/angular2/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export {URLSearchParams} from 'angular2/src/http/url_search_params';
4848
*
4949
* ```
5050
* import {httpInjectables, Http} from 'angular2/http';
51-
* @Component({selector: 'http-app', appInjector: [httpInjectables]})
51+
* @Component({selector: 'http-app', viewInjector: [httpInjectables]})
5252
* @View({template: '{{data}}'})
5353
* class MyApp {
5454
* constructor(http:Http) {

modules/angular2/src/core/annotations_impl/annotations.ts

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -822,8 +822,7 @@ export interface DirectiveArgs {
822822
* When a component is instantiated, Angular
823823
* - creates a shadow DOM for the component.
824824
* - loads the selected template into the shadow DOM.
825-
* - creates a child {@link Injector} which is configured with the `appInjector` for the
826-
* {@link Component}.
825+
* - creates all the injectable objects configured with `hostInjector` and `viewInjector`.
827826
*
828827
* All template expressions and statements are then evaluated against the component instance.
829828
*
@@ -865,59 +864,6 @@ export class Component extends Directive {
865864
*/
866865
changeDetection: string;
867866

868-
/**
869-
* Defines the set of injectable objects that are visible to a Component and its children.
870-
*
871-
* The `appInjector` defined in the Component annotation allow you to configure a set of bindings
872-
* for the component's
873-
* injector.
874-
*
875-
* When a component is instantiated, Angular creates a new child Injector, which is configured
876-
* with the bindings in
877-
* the Component `appInjector` annotation. The injectable objects then become available for
878-
* injection to the component
879-
* itself and any of the directives in the component's template, i.e. they are not available to
880-
* the directives which
881-
* are children in the component's light DOM.
882-
*
883-
*
884-
* The syntax for configuring the `appInjector` injectable is identical to {@link Injector}
885-
* injectable configuration.
886-
* See {@link Injector} for additional detail.
887-
*
888-
*
889-
* ## Simple Example
890-
*
891-
* Here is an example of a class that can be injected:
892-
*
893-
* ```
894-
* class Greeter {
895-
* greet(name:string) {
896-
* return 'Hello ' + name + '!';
897-
* }
898-
* }
899-
*
900-
* @Component({
901-
* selector: 'greet',
902-
* appInjector: [
903-
* Greeter
904-
* ]
905-
* })
906-
* @View({
907-
* template: `{{greeter.greet('world')}}!`,
908-
* directives: [Child]
909-
* })
910-
* class HelloWorld {
911-
* greeter:Greeter;
912-
*
913-
* constructor(greeter:Greeter) {
914-
* this.greeter = greeter;
915-
* }
916-
* }
917-
* ```
918-
*/
919-
appInjector: List<any>;
920-
921867
/**
922868
* Defines the set of injectable objects that are visible to its view dom children.
923869
*
@@ -960,9 +906,8 @@ export class Component extends Directive {
960906
*/
961907
viewInjector: List<any>;
962908

963-
constructor({selector, properties, events, host, exportAs, appInjector, lifecycle, hostInjector,
964-
viewInjector, changeDetection = DEFAULT,
965-
compileChildren = true}: ComponentArgs = {}) {
909+
constructor({selector, properties, events, host, exportAs, lifecycle, hostInjector, viewInjector,
910+
changeDetection = DEFAULT, compileChildren = true}: ComponentArgs = {}) {
966911
super({
967912
selector: selector,
968913
properties: properties,
@@ -975,13 +920,11 @@ export class Component extends Directive {
975920
});
976921

977922
this.changeDetection = changeDetection;
978-
this.appInjector = appInjector;
979923
this.viewInjector = viewInjector;
980924
}
981925
}
982926

983927
export interface ComponentArgs extends DirectiveArgs {
984-
appInjector?: List<any>;
985928
viewInjector?: List<any>;
986929
changeDetection?: string;
987930
}

modules/angular2/src/core/application.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,9 @@ function _createNgZone(givenReporter: Function): NgZone {
209209
* 1. It uses the component's `selector` property to locate the DOM element which needs to be
210210
* upgraded into
211211
* the angular component.
212-
* 2. It creates a new child injector (from the platform injector) and configures the injector with
213-
* the component's
214-
* `appInjector`. Optionally, you can also override the injector configuration for an app by
215-
* invoking
216-
* `bootstrap` with the `componentInjectableBindings` argument.
212+
* 2. It creates a new child injector (from the platform injector). Optionally, you can also
213+
* override the injector configuration for an app by
214+
* invoking `bootstrap` with the `componentInjectableBindings` argument.
217215
* 3. It creates a new `Zone` and connects it to the angular application's change detection domain
218216
* instance.
219217
* 4. It creates a shadow DOM on the selected component's host element and loads the template into
@@ -270,9 +268,9 @@ function _createNgZone(givenReporter: Function): NgZone {
270268
* - `appComponentType`: The root component which should act as the application. This is a reference
271269
* to a `Type`
272270
* which is annotated with `@Component(...)`.
273-
* - `componentInjectableBindings`: An additional set of bindings that can be added to `appInjector`
274-
* for the
275-
* {@link Component} to override default injection behavior.
271+
* - `componentInjectableBindings`: An additional set of bindings that can be added to the app
272+
* injector
273+
* to override default injection behavior.
276274
* - `errorReporter`: `function(exception:any, stackTrace:string)` a default error reporter for
277275
* unhandled exceptions.
278276
*

modules/angular2/src/core/compiler/dynamic_component_loader.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export class DynamicComponentLoader {
3030
* component's selector.
3131
* The loaded component receives injection normally as a hosted view.
3232
*/
33-
loadAsRoot(typeOrBinding: Type | Binding, overrideSelector: string = null,
34-
injector: Injector = null): Promise<ComponentRef> {
33+
loadAsRoot(typeOrBinding: Type | Binding, overrideSelector: string,
34+
injector: Injector): Promise<ComponentRef> {
3535
return this._compiler.compileInHost(typeOrBinding)
3636
.then(hostProtoViewRef => {
3737
var hostViewRef =
@@ -51,23 +51,23 @@ export class DynamicComponentLoader {
5151
* injection normally as a hosted view.
5252
*/
5353
loadIntoLocation(typeOrBinding: Type | Binding, hostLocation: ElementRef, anchorName: string,
54-
injector: Injector = null): Promise<ComponentRef> {
54+
bindings: ResolvedBinding[] = null): Promise<ComponentRef> {
5555
return this.loadNextToLocation(
5656
typeOrBinding, this._viewManager.getNamedElementInComponentView(hostLocation, anchorName),
57-
injector);
57+
bindings);
5858
}
5959

6060
/**
6161
* Loads a component next to the provided ElementRef. The loaded component receives
6262
* injection normally as a hosted view.
6363
*/
6464
loadNextToLocation(typeOrBinding: Type | Binding, location: ElementRef,
65-
injector: Injector = null): Promise<ComponentRef> {
65+
bindings: ResolvedBinding[] = null): Promise<ComponentRef> {
6666
return this._compiler.compileInHost(typeOrBinding)
6767
.then(hostProtoViewRef => {
6868
var viewContainer = this._viewManager.getViewContainer(location);
6969
var hostViewRef =
70-
viewContainer.create(hostProtoViewRef, viewContainer.length, null, injector);
70+
viewContainer.create(hostProtoViewRef, viewContainer.length, null, bindings);
7171
var newLocation = this._viewManager.getHostElement(hostViewRef);
7272
var component = this._viewManager.getComponent(newLocation);
7373

0 commit comments

Comments
 (0)