title: Angular2 - Injecting services by manually resolving the type runtime
body: <p>I couldn't figure out the right way to do it, but here is what I want to achieve:</p>
  
  <ul>
  <li><p>abstract class Engine</p></li>
  <li><p>class TurboEngine extends Engine</p></li>
  <li><p>class RocketEngine extends Engine</p></li>
  </ul>
  
  <p>I have an angular application which is injecting 'Engine' in a lot of places and using it's methods to fulfill the business needs.</p>
  
  <p>My only problem is that I have to inject TurboEngine and RocketEngine at the same time on every places and with a condition, decide which to call.</p>
  
  <p>This is what I want to change. Since I have an abstract Engine, I'd like to inject it ONCE in my main component, and then having injected automatically by that way in my components.</p>
  
  <p>So basically defining the provider for a service at runtime.</p>
  
  <p>Here is what I've tried, but didn't work:</p>
  
  <pre><code>var injector = ReflectiveInjector.resolveAndCreate([
      provide(Engine, {useClass: TurboEngine})
  ]);
  </code></pre>
  
  <p>I did it in my main component where it worked, but all other places I've got the following error:</p>
  
  <blockquote>
    <p>No provider for TurboEngine! (Engine -> TurboEngine)</p>
  </blockquote>
  
  <p>Updated:</p>
  
  <p>The way I want to use it:</p>
  
  <ul>
  <li><p>I have component <code>A</code> which injects Engine (that's where I want to choose an implementation, so either TurboEngine or RocketEngine based on some conditions.</p></li>
  <li><p>Then I have component <code>B</code>, which is inside component <code>A</code>'s template. Here when I'm trying to inject <code>Engine</code> I would expect to have the same instantiated object as I manually created in component <code>A</code></p></li>
  </ul>