Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce LifecycleCoroutineScopeFactory #144

Closed
RBusarow opened this issue Jul 12, 2020 · 0 comments · Fixed by #145
Closed

Introduce LifecycleCoroutineScopeFactory #144

RBusarow opened this issue Jul 12, 2020 · 0 comments · Fixed by #145
Labels
enhancement New feature or request
Milestone

Comments

@RBusarow
Copy link
Owner

If using LifecycleCoroutineScope but not using the lifecycleScope extension, the current best option for providing a custom scope/context via DI like Dagger may look like this:

class SomeFragment @Inject constructor(
  coroutineScope: MainImmediateCoroutineScope
) : Fragment() {

  private val lifecycleScope = LifecycleCoroutineScope(this, coroutineScope)

  // ...
}

This isn't terrible, since everything important is in the injected scope, but it can be improved.

class SomeFragment @Inject constructor(
  lifecycleCoroutineScopeFactory: LifecycleCoroutineScopeFactory
) : Fragment() {

  private val lifecycleScope = lifecycleCoroutineScopeFactory.create(this)

  // ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
1 participant