title: Boundary Callback (Android Paging Library) with CoroutineScope
body: <p>I'm trying to implement <code>Android Paging library</code> with <code>ViewModel</code> and <code>Kotlin Coroutines</code></p>
  
  <p>I have a <code>ViewModel</code> that implements <code>CoroutineScope</code>. It depends on <code>Repository</code>:</p>
  
  <pre><code>class MovieListViewModel(
      private val movieRepository: MovieRepository
  ) : ViewModel(), CoroutineScope {
  
      private val job = Job()
      override val coroutineContext: CoroutineContext
          get() = job + Dispatchers.IO
  
      private lateinit var _movies: LiveData&lt;PagedList&lt;MovieBrief&gt;&gt;
  
      val movies: LiveData&lt;PagedList&lt;MovieBrief&gt;&gt;
          get() = _movies
  
      init {
          launch {
              _movies = LivePagedListBuilder(movieRepository.getMovies(), DATABASE_PER_PAGE)
                  .setBoundaryCallback(movieRepository.movieBoundaryCallback)
                  .build()
          }
      }
  
  }
  </code></pre>
  
  <p>And This is my <code>Repository</code>. I inject the <code>BoundaryCallback</code> with <code>Kodein</code> Dependecy Injector.</p>
  
  <pre><code>class MovieRepositoryImpl(
      private val movieDao: MovieDao,
      boundaryCallback: MovieBoundaryCallback
  ) : MovieRepository {
  
      override suspend fun getMovies(): DataSource.Factory&lt;Int, MovieBrief&gt; {
          return movieDao.getMovies()
      }
  
      override val movieBoundaryCallback = boundaryCallback
  
  }
  </code></pre>
  
  <p>Inside <code>BoundaryCallback</code> class The <code>onItemAtEndLoaded</code> calls the RESTAPI and then saves the data to Room database (both are suspending functions). So I have to access my ViewModel's coroutine scope. What is the best practice to achieve this?</p>
  
  <p>Thanks</p>