title: Injecting dependencies into background service in Dagger2
body: <p>I have <code>Shared Preferences</code> as a dagger singleton component. I need to inject it into background services like <code>FirebaseInstanceService</code>. Here's my attempt:</p>
  
  <pre><code>public class InstanceIDListenerService extends FirebaseInstanceIdService {
      @Inject
      Preferences preferences;
  
      @Override
      public void onTokenRefresh() {
          ((MyApp) getApplication()).getSingletonComponent().inject(this);
          String refreshedToken = FirebaseInstanceId.getInstance().getToken();
          preferences.setFcmToken(refreshedToken);
  
      }
  }
  </code></pre>
  
  <p>It is used in this way:</p>
  
  <pre><code>   &lt;service android:name="com.fcm.InstanceIDListenerService"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.google.firebase.INSTANCE_ID_EVENT" /&gt;
              &lt;/intent-filter&gt;
     &lt;/service&gt;
  </code></pre>
  
  <p>Should I use <code>((MyApp) getApplication()).getSingletonComponent().inject(this);</code> in the <code>onTokenRefresh</code> listener? Is this the correct listener to inject dependencies?</p>