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

Provided UseCases at ViewModelScope instead of Singleton #139

Merged
merged 1 commit into from
Oct 5, 2022

Conversation

Devendra34
Copy link
Contributor

Fixes #116

Earlier all the UseCases were provided as singleton to each and every ViewModel. Means a single instance of a particular UseCase was shared across various ViewModels. In this way, even if any UseCases is not required by a ViewModel, it was still there in application level scope.
Now, all the UseCases are scoped by @ViewModelScope. Means it will be provided to a ViewModel only when it is required. Also If two (or more) ViewModels are using same type of UseCases then the instance of use-case for each of them would be different. (Read more in the articles mentioned below, especially the last two).
Articles referred:

  1. Dependency Injection with Hilt
  2. Using Hilt’s ViewModelComponent
  3. Hilt View Models from dagger.dev

Copy link
Owner

@hieuwu hieuwu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ! Nice. I love technical PRs including document and detailed explaination

@hieuwu hieuwu merged commit 645246c into hieuwu:main Oct 5, 2022
@Devendra34
Copy link
Contributor Author

LGTM ! Nice. I love technical PRs including document and detailed explaination

Thanks @hieuwu. I'm glad you liked the PR.
Kudos to you as well for maintaining such an awesome repository with best practices!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide dependencies at right scope
2 participants