<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>
If a <em>dependency</em> (e.g. <code class="notranslate">ServiceA</code>) is injected into a <em>guard</em> (e.g. <code class="notranslate">GuardA</code>; service, that implements <code class="notranslate">CanActivate</code> interface), in a <em>feature module</em> (e.g. <code class="notranslate">FeatureModule</code>), that is lazy loaded, and both <code class="notranslate">ServiceA</code> and <code class="notranslate">GuardA</code> are defined in that <code class="notranslate">FeatureModule</code>, than <code class="notranslate">GuardA</code> gets it's own dedicated version of the <code class="notranslate">ServiceA</code>, whereas other <em>components</em> and <em>services</em>, defined at the <em>feature module</em> get their own version of the <code class="notranslate">ServiceA</code>, that is shared among them. Basically <em>injected service</em> isn't a singleton anymore. I think it's related to how the <code class="notranslate">RouterModule</code> works with <em>DI</em>.</p>
<p dir="auto"><strong>Expected behavior</strong><br>
All <em>guards</em>, <em>services</em> and <em>components</em> of a <em>feature module</em>, get the same service instance, that is injected into them. So in the provided plunker the<code class="notranslate">FeatureService</code> should be created only once.</p>
<p dir="auto"><strong>Minimal reproduction of the problem with instructions</strong><br>
Here is a plunker <a href="https://plnkr.co/cYjMbvgJEciKg00GSNfb" rel="nofollow">https://plnkr.co/cYjMbvgJEciKg00GSNfb</a><br>
When the <code class="notranslate">Feature</code> link is clicked, then <code class="notranslate">FeatureModule</code> is lazy loaded. <code class="notranslate">FeatureComponent</code> is displayed and it contains a template with a random number, that is provided by an injected <code class="notranslate">FeatureService</code>. When <code class="notranslate">Feature child</code> link is clicked, <code class="notranslate">FeatureChildGuard</code> gets activated and a alert box with a value, that is provided by the <code class="notranslate">FeatureService</code> is provided and it differs from the one, that is displayed in the <code class="notranslate">FeatureComponent</code>, because dedicated <code class="notranslate">FeatureService</code> is created for that guard (you can also see it in <code class="notranslate">console.log</code> calls).</p>
<p dir="auto"><strong>What is the motivation / use case for changing the behavior?</strong><br>
Each feature module is assumed to be an isolated and self-contained piece of program logic, so everything, that is defined in this module, that is intended to be singleton should be it. And <code class="notranslate">CanActivate</code> logic can be related to a current state of a feature module service and not only the ones, that are defined at the top-most level of angular app.</p>
<p dir="auto"><strong>Please tell us about your environment:</strong> OS X Sierra 10.12.1, WebStorm 2016.3.3, node 6.9.1, angular-cli 1.0.0-beta.25.5 (but I guess this information is not important, as it's reproducible in browser)</p>
<ul dir="auto">
<li>
<p dir="auto"><strong>Angular version:</strong> 2.4.5</p>
</li>
<li>
<p dir="auto"><strong>Browser:</strong> all</p>
</li>
<li>
<p dir="auto"><strong>Language:</strong> TypeScript 2.0</p>
</li>
</ul>
<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>