title: How to inject into static classes using Dagger?
body: <p>I want to introduce dependency injection through <a href="http://square.github.io/dagger/">Dagger</a> to a project. The following code acts as an example to describe the problem of <strong>injection into static classes</strong>.</p>
  
  <p>The static method <code>setupTextView()</code> is called from multiple classes:</p>
  
  <pre><code>public abstract class TextViewHelper {
      public static void setupTextView(TextView textView, 
                                       Spanned text, 
                                       TrackingPoint trackingPoint) {
          textView.setText(text, TextView.BufferType.SPANNABLE);
          textView.setMovementMethod(LinkMovementMethod.getInstance());
          textView.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  MyApp.getTracker().track(trackingPoint);
              }
          });
      }
  }
  </code></pre>
  
  <p>Here is one example how the helper method is used:</p>
  
  <pre><code>TextViewHelper.setupTextView(this, R.id.some_text_view, 
                               R.string.some_text,
                               TrackingPoint.SomeTextClick);
  </code></pre>
  
  <p>The tracking used in the helper method is provided by the application class:</p>
  
  <pre><code>public class MyApp extends Application {
  
      private static Tracking mTracking;
  
      public void onCreate() {
          super.onCreate();
          mTracking = getTracking(getApplicationContext());
      }
  
      private Tracking getTracking(Context context) {
          if (BuildConfig.DEBUG) {
              return new NoTracking();
          } else {
              return new NsaTracking(context);
          }
      }
  
      public static Tracking getTracker() {
          return mTracking;
      }
  
  }
  </code></pre>
  
  <p>Now, I want to inject the tracking via Dagger. When I refactored the code I noticed that I would need to pass the tracking object from my Activity or Fragment to the static helper since I cannot directly inject into the static class:</p>
  
  <pre><code>TextViewHelper.setupTextView(this, R.id.some_text_view, 
                               R.string.some_text, 
                               TrackingPoint.SomeTextClick,
                               Tracking tracking);
  </code></pre>
  
  <p>This does not feel like a good design pattern - since I pass the <code>TrackPoint</code> and the <code>Tracking</code> object. How would you improve this?</p>