architecture-components-samples
architecture-components-samples copied to clipboard
'WorkManagerSample' should use Hilt and App Startup library to initialize and provide WorkManager dependency
Description
Hilt should be used along with App Startup's Initializer interface to provide a WorkManager instance on first access.
WorkManager should be initialized on-demand rather than when the app starts.
WorkManager instance should be injected into the ViewModel.
Files that require refactoring so as to use @ HiltWorker
Classes to add, so that we can use dependency injection for WorkManager instance:
-
object class WorkManagerInitializerModule (Hilt Module) in the di package (separate package for the WorkManagerSample app).
-
WorkManagerInitializerModule would implement Initializer< WorkManager > .
Tasks
- [x] Write a @ Provides method by overriding Initializer < WorkManager >'s create() method inside a Hilt Module.
- [x] consume the WorkManager dependency inside the viewmodel's constructor.
- [x] Refactor the worker classes to use @HiltWorker.
- [x] All relevant classes to use appropriate Hilt annotations.