title: Global instance of provider in Ionic 3
body: <p>I have a provider that has to be always up when the app is running to watch for the network connection status. </p>
  
  <p>So according to that <a href="https://www.joshmorony.com/an-in-depth-explanation-of-providers-in-ionic-2/" rel="nofollow noreferrer">tutorial</a> I have added the class to my  <code>app.module.ts</code> file to make it a <em>global instance</em>. So as far as I understand it, the service should be up when the app initializes it's root component (thus <code>app.module.ts</code>).</p>
  
  <p><strong>Problem</strong>: The provider gets not called until a specific page of the app imports and uses it. </p>
  
  <p>In the mentioned tutorial the <code>provider</code> is imported like that: </p>
  
  <pre><code>ionicBootstrap(MyApp, [TestProvider]);
  </code></pre>
  
  <p>Unfortunately that does not work for me. That <a href="https://stackoverflow.com/a/42500528/4125633">post</a> says that this quite new tutorial is outdated. </p>
  
  <p><strong>Question</strong>: How could I use <code>providers</code> in <code>Ionic 3</code> that they are available as <em>one instance</em> after launching the application?</p>
  
  <p>My app.module.ts:</p>
  
  <pre><code>import { NetworkConnectionProvider } from '../providers/networkconnection/networkconnection';
  // (...)
  
  @NgModule({
    declarations: [
      MyApp,
      // (...)
    ],
    imports: [
      BrowserModule,
      HttpModule,
      IonicModule.forRoot(MyApp),
      ionicGalleryModal.GalleryModalModule,
    ],
    bootstrap: [
      IonicApp
    ],
    entryComponents: [
      MyApp,
      // (...)
    ],
    providers: [
      // (...)
      NetworkConnectionProvider
    ]
  })
  export class AppModule {}
  </code></pre>
  
  <p>My provider:</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import { Http } from '@angular/http';
  import 'rxjs/add/operator/map';
  import { Network } from '@ionic-native/network';
  
  
  @Injectable()
  export class NetworkConnectionProvider {
    private TAG = "NetworkConnectionProvider ";
  
    private isConnectedToInternet: Boolean;
  
    constructor(
      public http: Http,
      public network: Network
      ) {
  
      this.isConnectedToInternet = true;
  
      let disconnectSubscription = this.network.onDisconnect().subscribe(() =&gt; {
        console.log(this.TAG + 'network was disconnected.');
        this.isConnectedToInternet = false;
      });
  
      // watch network for a connection
      let connectSubscription = this.network.onConnect().subscribe(() =&gt; {
        console.log('network connected!');
        this.isConnectedToInternet = true;
  
        // We just got a connection but we need to wait briefly
        // before we determine the connection type. Might need to wait.
        // prior to doing any api requests as well.
        setTimeout(() =&gt; {
          if (this.network.type === 'wifi') {
            console.log(this.TAG + 'wifi connection available');
          }
        }, 3000);
      });
  
      console.log('Hello NetworkConnectionProvider');
    }
  
    public subscribeOnConnect() {
      return this.network.onConnect();
    }
  
    public isConnected(): Boolean{
      return this.isConnectedToInternet;
    }
  
    public getConnectionType(): string {
      return this.network.type;
    }
  
  }
  </code></pre>