Presenter injection with Dagger 2
<p>I just started using Dagger 2 and I found online thousands guides each one with a different implementation and I'm a bit confused now.
So basically this is what I wrote at the moment:</p>

<p>AppModule.java:</p>

<pre><code>@Module
public class AppModule {

 Application mApplication;

 public AppModule(Application application) {
    mApplication = application;
 }

 @Provides
 @Singleton
 Application providesApplication() {
    return mApplication;
 }
}
</code></pre>

<p>DataModule.java:</p>

<pre><code>@Module
public class DataModule {

private static final String BASE_URL = "http://beta.fridgewizard.com:9001/api/";

@Provides
@Singleton
NetworkService provideNetworkService() {
    return new NetworkService(BASE_URL);
}

@Provides
@Singleton
SharedPreferences provideSharedPreferences(Application app) {
    return PreferenceManager.getDefaultSharedPreferences(app);
}
}
</code></pre>

<p>PrefsModel.java:</p>

<pre><code>@Module(includes = DataModule.class)
public class PrefsModel {

@Provides
@Singleton
QueryPreferences provideQuery(SharedPreferences prefs) {
    return new QueryPreferences(prefs);
}
}
</code></pre>

<p>AppComponent.java (I'm exposing QueryPreferences object since I need it in a presenter, hopefully is correct in this way):</p>

<pre><code>@Singleton
@Component(modules = {AppModule.class, DataModule.class, PrefsModel.class})
public interface AppComponent {

    void inject(HomeFragment homeFragment);

    QueryPreferences preferences();
    NetworkService networkService();
}
</code></pre>

<p>Then I have the FwApplication.java:</p>

<pre><code>public class FwApplication extends Application {

private static final String TAG = "FwApplication";

private NetworkService mNetworkService;

private AppComponent mDataComponent;

    @Override
    public void onCreate() {
       super.onCreate();

       buildComponentAndInject();
    }

    public static AppComponent component(Context context) {
      return ((FwApplication)   context.getApplicationContext()).mDataComponent;
    }

    public void buildComponentAndInject() {
       mDataComponent = DaggerComponentInitializer.init(this);
    }

    public static final class DaggerComponentInitializer {
      public static AppComponent init(FwApplication app) {
        return DaggerAppComponent.builder()
                .appModule(new AppModule(app))
                .dataModule(new DataModule())
                .build();
    }
   }
}
</code></pre>

<p>Finally I added another module for the presenters:</p>

<pre><code>@Module
public class PresenterModule {

   @Provides
   Presenter&lt;FwView&gt; provideHomePresenter(NetworkService networkService) {
      return new HomePresenterImpl(networkService);
   }

   @Provides
   Presenter&lt;FwView&gt; provideSearchPresenter(NetworkService networkService) {
      return new SearchPresenterImpl(networkService);
   }

}
</code></pre>

<p>And the following component (which returns error because I cannot add a scoped dependencies here):</p>

<pre><code>@Component(dependencies = AppComponent.class, modules = PresenterModule.class)
public interface PresenterComponent {

    void inject(HomePresenterImpl presenter);
}
</code></pre>

<p>So, I have few questions that are not clear for me reading the documentation online:</p>

<ul>
<li>How can I fix the error in the presenter component since it depends on NetworkService which is a singleton defined in the AppComponent?</li>
<li>I have an HomeFragment which should implement the HomePresenter with "new HomePresenter(networkService)" but now I don't know how to use the DI defined</li>
</ul>

<p><strong>EDIT - FIX:</strong></p>

<p>HomeFragment.java:</p>

<pre><code>public class HomeFragment extends Fragment {

private static final String TAG = "FW.HomeFragment";


@Inject
HomePresenterImpl mHomePresenter;

public static HomeFragment newInstance() {
    return new HomeFragment();
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FwApplication.component(getActivity()).inject(this);
}
</code></pre>

<p>Then I modified the presenter constructor in this way:</p>

<pre><code>@Inject
public HomePresenterImpl(NetworkService networkService) {
    mNetworkService = networkService;
    mInteractor = new InteractorImpl(mNetworkService);
}
</code></pre>

<p>Then NetworkService is injected automatically.</p>

<p>I was wondering if it is correct in this way since I have to call for every fragment I have that needs a presenter constructed in the same way as the one above the following code:</p>

<pre><code>FwApplication.component(getActivity()).inject(this);
</code></pre>