Passing data to PageKeyedDataSource : <p>I am using <a href="https://developer.android.com/reference/android/arch/paging/PageKeyedDataSource.LoadInitialCallback" rel="noreferrer">PageKeyedDataSource</a> to make paging by calling an API and using Retrofit.</p>

<p>And I am using <strong>Dagger 2</strong> to make the dependency injection.</p>

<pre><code>@Provides
Repository provideRepository(...) {
    ...
}

@Provides
PageKeyedVideosDataSource providePageKeyeVideosDataSource(Repository repository) {
    ...
}

@Provides
VideoDataSourceFactory provideVideoDataSourceFactory(PageKeyedHomeVideosDataSource pageKeyedHomeVideosDataSource) {
    ...
}

@Provides
ViewModelFactory provideViewModelFactory(Repository repository, VideoDataSourceFactory videoDataSourceFactory) {
    ...
}
</code></pre>

<p>Now, I need to do the same thing, however my call needs a new parameter: an id. </p>

<pre><code>@GET(Urls.VIDEOS_BY_CATEGORY)
    Observable&lt;RequestVideo&gt; getVideosByCategory(
            @Path("id") int categoryId,  // &lt;-- Now I need this new parameter
            @Query("per-page") int perPage,
            @Query("page") int page);
</code></pre>

<p>Before, my PageKeyedVideosDataSource needed only the page and the per-page to make the call, it was easy. However, now I need to put this new parameter id dynamically inside the PageKeyedDataSource.</p>

<p>I saw <a href="https://github.com/googlesamples/android-architecture-components/tree/master/PagingWithNetworkSample" rel="noreferrer">PagingWithNetworkSample</a> and figured it out that they put a new parameter in PagedKeyedDataSource by adding it in the constructor. Then, I thought about doing this:</p>

<pre><code>public PageKeyedCategoryVideosDataSource(int categoryId, Repository repository) {
    this.categoryId = categoryId;
    this.repository = repository;
}
</code></pre>

<p>However, if I add the id in the constructor, I think I'll not be able to use dagger 2 anymore because by using dagger 2 the PageKeyedVideosDataSource is not created dynamically, therefore, I can't keep changing the value of the id.</p>

<p>I need to create the PageKeyedDataSource dynamically like this:</p>

<pre><code>int categoryId = getCategoryId();
PageKeyedVideosDataSource dataSource = new PageKeyedVideosDataSource(categoryId, repository);
</code></pre>

<ul>
<li>Should I do this and not use Dagger 2?</li>
<li>Is it possible to dynamically create the DataSource still using Dagger 2?</li>
</ul>
