title: Inject service in a simple class constructor with Angular2
body: <p>I created a Message class like this</p>
  
  <pre><code>import { ReflectiveInjector } from '@angular/core';
  
  import { ApiService } from '../api.service';
  
  export class Message {
          timestamp: number;
          message: any;
          api: ApiService;
  
          constructor(message: any) {
                  let injector = ReflectiveInjector.resolveAndCreate([ApiService]);
                  this.api = injector.get(ApiService);
                  this.timestamp = message.timestamp;
                  this.message = message.message;
          }
  }
  </code></pre>
  
  <p>I'm not injecting <em>ApiService</em> directly in the constructor parameters because I'm trying to avoid this:
  <code>let nm = new Message(message, this.api)</code><br>
  I don't want the service to be in the parameters.</p>
  
  <p>So I'm using the ReflectiveInjector but this code doesn't even work. I get this error : <strong>EXCEPTION: Error: Uncaught (in promise): No provider for Http! (ApiService -> Http)</strong> even if I include <em>HTTP_PROVIDERS</em> this way</p>
  
  <pre><code>import { bootstrap } from '@angular/platform-browser-dynamic';
  import { enableProdMode } from '@angular/core';
  import { HTTP_PROVIDERS } from '@angular/http';
  
  import { AppComponent, environment } from './app/';
  import { appRouterProviders } from './app/app.routes';
  
  if (environment.production) {
    enableProdMode();
  }
  
  bootstrap(AppComponent, [
          appRouterProviders,
          HTTP_PROVIDERS,
  ])
  .catch(err =&gt; console.log(err));
  </code></pre>
  
  <p>How can I use the constructor to instantiate my class and inject my services like this :<br>
  <code>let nm = new Message(message);</code></p>
  
  <p>Thanks</p>