Android-Weekly icon indicating copy to clipboard operation
Android-Weekly copied to clipboard

Dagger and Coroutine improvements.

Open nikhilbansal97 opened this issue 5 years ago • 4 comments

Dagger:

  1. In the AppComponent, there is Builder which can be replaced with the interface Factory : AndroidInjector.Factory<MyApplication> as Builder is deprecated in the latest version of Dagger.
  2. The fun inject(instance: MyApplication) can be removed as DaggerApplication class handles the field injections in the Application class.
  3. The @BindsInstance function can be removed as the Factory generates this code for us.

Coroutines:

  1. We can use withContext() function to switch threads in a coroutine instead of launching a new coroutine in separate thread each time.
  2. Every function should handle the thread switching for proper execution of its body instead of relying on the caller of the function.
  3. There is no thread switching needed for the database operations if the function in Dao is marked as suspend. Room uses a custom dispatcher optimised for the database operations.

nikhilbansal97 avatar Dec 08 '19 18:12 nikhilbansal97

@nikhilbansal97 Thank you, could you contribute to this?

mnayef95 avatar Dec 08 '19 21:12 mnayef95

Sure! Already working on it! 😀

nikhilbansal97 avatar Dec 09 '19 02:12 nikhilbansal97

@nikhilbansal97 Thank you :D

mnayef95 avatar Dec 10 '19 00:12 mnayef95

Hi @nikhilbansal97 Sorry for bothering you, but I want to ask if there is any update from your side, or should I work on it?

mnayef95 avatar Dec 14 '19 19:12 mnayef95