Issue 1:
I'm submitting a ... (check one with "x")

[X] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Under certain conditions where module dependencies are listed in particular import orders, values that are provided with the multi flag (such as via a forChild syntax) will be duplicated when application boots.

This behavior does not occur in angular 2.2.1 and was observed in 2.3.0 and 2.4.0.

Expected behavior

Values provided within a module should not be duplicated if the module is referenced by several others.

Minimal reproduction of the problem with instructions

I've narrowed down the situation when this occurs to this plunker. When run, you can see the list of provided values printed to the DOM. When the problem occurs, the string 'shared' will be printed twice.

In this example there are 5 modules--AppModule, FeatureModule, FeatureWidgetModule, SharedModule, WidgetModule.

The WidgetModule exposes a forChild method which simply provides string arguments as a multiple provider.

The SharedModule imports WidgetModule.forChild('shared').

The FeatureModule follows a pattern often seen in Router documentation where there is a secondary module dedicated to importing the routes (or in this case widgets) for a feature. So, FeatureModule imports FeatureWidgetModule which imports WidgetModule.forChild('feature').

Finally, the AppModule imports both FeatureModule and SharedModule.

When we use this setup, using the specific import order in the punker, the value 'shared' that was multi-provided by the SharedModule appears twice when we inspect all provided widgets.

If you change the import order of the modules in the plunker you will see that 'shared' is only printed once.

What is the motivation / use case for changing the behavior?

My use case is to allow various feature modules to provide their own values (such as route definitions) in a larger application with some shared modules referenced by several others. While i can work around the issue by manually manipulating the import orders, it requires that every module writer understand all the dependencies of the modules upon which they depend, which I believe should not be their concern.

Please tell us about your environment:

Using OSX, WebStorm, npm,

Able to reproduce using both SystemJS and Webpack

Angular version: 2.4.0

Problem occurs in angular 2.3.0 and 2.4.0.

Does not occur in 2.2.1.

Browser: [all]

Language: [TypeScript 2.1.1]

Node (for AoT issues): node --version = 6.9.1

Issue 2:
I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

In the angular.io project we rely on a fake xhr implementation to simulate a web api in our samples. The implementation can be found here: https://github.com/angular/in-memory-web-api/blob/master/src/in-memory-backend.service.ts#L120

To short circuit the injection of XHRBackend, we provide the fake backend like this:

{ provide: XHRBackend, useClass: InMemoryBackendService }

This approach works well for JIT compiled samples, but for some reason this does not work when doing AOT compilation.

The compile error I am seeing is:

Error: Error at /Users/tor/Helgevold-Consulting-Dev/angular.io/public/docs/_examples/toh-6/ts/app/app.module.ngfactory.ts:219:67: Supplied parameters do not match any signature of call target.
Error at /Users/tor/Helgevold-Consulting-Dev/angular.io/public/docs/_examples/toh-6/ts/app/app.module.ngfactory.ts:227:75: Argument of type 'InMemoryBackendService' is not assignable to parameter of type 'XHRBackend'.
Property '_browserXHR' is missing in type 'InMemoryBackendService'.

It complains that _browserXHR is not defined in the class.

I tried defining _browserXHR, but that leads me to the new error:

Argument of type 'InMemoryBackendService' is not assignable to parameter of type 'XHRBackend'.
Types have separate declarations of a private property '_browserXHR'.

I am not sure why this doesn't AOT compile. Why is it comparing internal (private) properties between the two implementations?

Thanks!