<p dir="auto"><strong>I'm submitting a ...</strong>  (check one with "x")</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[X ] bug report =&gt; search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request =&gt; Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

This is my lazily loaded module. It has AppContainerService in its provider and a Module11GaurdService for protecting a route to Module11Component, which is also lazily routed from Module1Component

import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { Module1Component } from './module1.component';
import { AppContainerService } from './module1.statecontainer';
import { module11GaurdService } from './module11/module11.gaurd';
const routes = RouterModule.forChild([
    {
        path: '',
        component: Module1Component,
        children: [{
            path: 'module11',
            loadChildren: 'app/module1/module11/module11.module#module11',
            canActivate: [module11GaurdService]
        }]
    }]);
@NgModule({
    imports: [routes],
    exports: [],
    declarations: [Module1Component],
    providers: [AppContainerService, module11GaurdService],
})
export class module1 { }

I am requesting a instance of AppContainerService in Module1Component' constructor.

import { Component, OnInit, Injector } from '@angular/core';
import { AppContainerService} from './module1.statecontainer';
@Component({
  selector: 'app-module1',
  templateUrl: './module1.component.html',
  styleUrls: ['./module1.component.css']
})
export class Module1Component implements OnInit {

  constructor(conatainer:AppContainerService) { 
  }

  ngOnInit() {
  }

}
This is my Module1Component's gaurd. Where also I am requesting an instance of AppContainerService in constructor

import { Injectable, Injector } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
import { AppContainerService} from '../module1.statecontainer';
@Injectable()
export class module11GaurdService implements CanActivate{

    constructor(container: AppContainerService) { 
        //let x = injector.get(AppContainerService);
        debugger;
    }

    canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):  boolean{
        return true;
    }

}

this is my Module11Component

import { Component, OnInit } from '@angular/core';
import { AppContainerService} from '../module1.statecontainer';

@Component({
  selector: 'app-module11',
  templateUrl: './module11.component.html',
  styleUrls: ['./module11.component.css']
})
export class Module11Component implements OnInit {

  constructor(private container:AppContainerService) { }

  ngOnInit() {
  }

}
**Current behavior**

When I am navigating to ~/module1 for **first time** an instance of AppContainer Service is created as expected for Module1Component. But when I am naviagting to ~/module1/module11 from Module1Component a new instance of AppContainerService is created for Module11GaurdService, which shouldnt be the case as AppContainerService instance is already created and injected within the child injector of Module1 and Module11GaurdService is also within Module1 Provider. So if I am updating anything in AppContainer in the gaurd it is not reflected in the AppContainer instance in Module11Component.

Same problem doesnt occur **after first time** navigation of module1 or module11.After subsequent navigation to module1 again  AppContainer Service is created in Module1Component and shared with Gaurd and Module11Component. On a different note Gaurd service is only created once for the first time routing, on subsequent navigation to module11 no new instances of gaurd is created.

**Please tell us about your environment:**
windows 7, VsCode1.8, node 7.3.0

* **Angular version:** 
angular2(2.4.4), angular-cli(beta26)

* **Browser:** [all ]

 
* **Language:** [TypeScript 2.0 ]
"><pre class="notranslate"><code class="notranslate">[X ] bug report =&gt; search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request =&gt; Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

This is my lazily loaded module. It has AppContainerService in its provider and a Module11GaurdService for protecting a route to Module11Component, which is also lazily routed from Module1Component

import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { Module1Component } from './module1.component';
import { AppContainerService } from './module1.statecontainer';
import { module11GaurdService } from './module11/module11.gaurd';
const routes = RouterModule.forChild([
    {
        path: '',
        component: Module1Component,
        children: [{
            path: 'module11',
            loadChildren: 'app/module1/module11/module11.module#module11',
            canActivate: [module11GaurdService]
        }]
    }]);
@NgModule({
    imports: [routes],
    exports: [],
    declarations: [Module1Component],
    providers: [AppContainerService, module11GaurdService],
})
export class module1 { }

I am requesting a instance of AppContainerService in Module1Component' constructor.

import { Component, OnInit, Injector } from '@angular/core';
import { AppContainerService} from './module1.statecontainer';
@Component({
  selector: 'app-module1',
  templateUrl: './module1.component.html',
  styleUrls: ['./module1.component.css']
})
export class Module1Component implements OnInit {

  constructor(conatainer:AppContainerService) { 
  }

  ngOnInit() {
  }

}
This is my Module1Component's gaurd. Where also I am requesting an instance of AppContainerService in constructor

import { Injectable, Injector } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
import { AppContainerService} from '../module1.statecontainer';
@Injectable()
export class module11GaurdService implements CanActivate{

    constructor(container: AppContainerService) { 
        //let x = injector.get(AppContainerService);
        debugger;
    }

    canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):  boolean{
        return true;
    }

}

this is my Module11Component

import { Component, OnInit } from '@angular/core';
import { AppContainerService} from '../module1.statecontainer';

@Component({
  selector: 'app-module11',
  templateUrl: './module11.component.html',
  styleUrls: ['./module11.component.css']
})
export class Module11Component implements OnInit {

  constructor(private container:AppContainerService) { }

  ngOnInit() {
  }

}
**Current behavior**

When I am navigating to ~/module1 for **first time** an instance of AppContainer Service is created as expected for Module1Component. But when I am naviagting to ~/module1/module11 from Module1Component a new instance of AppContainerService is created for Module11GaurdService, which shouldnt be the case as AppContainerService instance is already created and injected within the child injector of Module1 and Module11GaurdService is also within Module1 Provider. So if I am updating anything in AppContainer in the gaurd it is not reflected in the AppContainer instance in Module11Component.

Same problem doesnt occur **after first time** navigation of module1 or module11.After subsequent navigation to module1 again  AppContainer Service is created in Module1Component and shared with Gaurd and Module11Component. On a different note Gaurd service is only created once for the first time routing, on subsequent navigation to module11 no new instances of gaurd is created.

**Please tell us about your environment:**
windows 7, VsCode1.8, node 7.3.0

* **Angular version:** 
angular2(2.4.4), angular-cli(beta26)

* **Browser:** [all ]

 
* **Language:** [TypeScript 2.0 ]

</code></pre></div>
<p dir="auto"><strong>I'm submitting a ...</strong>  (check one with "x")</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[x] bug report =&gt; search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request =&gt; Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question"><pre class="notranslate"><code class="notranslate">[x] bug report =&gt; search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request =&gt; Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
</code></pre></div>
<p dir="auto"><strong>Current behavior</strong><br>
After upgrading to router 3.2.0, services being provided by component module are being instantiated twice. Once while resolver is being run (last place in router is PreActivation.prototype.getToken)  and then again later during activation (last place in router is RouterOutlet.prototype.activate).<br>
Upgrading rest of Angular to 2.2.0 and leaving router at 3.1.1 it works as it used to (and looking in debugger I see service is only instantiated from PreActivation.prototype.getToken)</p>
<p dir="auto"><strong>Expected behavior</strong></p>

<p dir="auto">Providers should only be instantiated once - as they are when using router version 3.1.1</p>
<p dir="auto"><strong>Minimal reproduction of the problem with instructions</strong></p>

<p dir="auto">Haven't yet reproduced in a plnkr but my use case has a lazy loaded component that itself has sub components (not lazy loaded). The sub component has a resolver that uses a service, and the sub component itself uses the service. The service is included in the lazy loaded components module providers list and is being instantiated twice. Once apparently while router is working on resolve and once when component is being activated.</p>
<p dir="auto"><strong>What is the motivation / use case for changing the behavior?</strong></p>

<p dir="auto">Its just wrong, and my service fetches data on initialization so extra instance causes extra fetch. This does not happen with router 3.1.1 (never tried 3.1.2 as deactivate guards don't work correctly in that version)</p>
<p dir="auto"><strong>Please tell us about your environment:</strong></p>

<p dir="auto">Windows 10, Visual Studio Code, angular-cli: 1.0.0-beta.19-3 ng serve</p>
<ul dir="auto">
<li><strong>Angular version:</strong> 2.0.X</li>
</ul>

<p dir="auto">2.2.0</p>
<ul dir="auto">
<li><strong>Browser:</strong> [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]</li>
</ul>

<p dir="auto">Only tried in Chrome</p>
<ul dir="auto">
<li>
<p dir="auto"><strong>Language:</strong> [all | TypeScript X.X | ES6/7 | ES5]<br>
Typescript 2.0.9</p>
</li>
<li>
<p dir="auto"><strong>Node (for AoT issues):</strong> <code class="notranslate">node --version</code> =</p>
</li>
</ul>