-
-
Notifications
You must be signed in to change notification settings - Fork 393
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
How to inject shared one instance of ViewModule to different fragments? #23
Comments
Hi @DigitalKoi, First of all, thanks for your question. The quick answer is yes it's possible, but let explain how to do it. Each You cand have just one |
when I try to do something like this
I receive message |
Please correct me if I'm wrong @DigitalKoi. I'm confused about the Basically the @Inject
lateinit var secondViewModel: SecondViewModelClass For my point of view you should have the following code, and to make it easier I will use code naming classes. Imagine that I want to use the For this reason, we should include it to @FeatureScope
@Provides
fun providesCharacterDetailViewModel(
marvelRepository: MarvelRepository,
characterFavoriteRepository: CharacterFavoriteRepository,
characterDetailMapper: CharacterDetailMapper
) = fragment.viewModel {
CharacterDetailViewModel(
marvelRepository = marvelRepository,
characterFavoriteRepository = characterFavoriteRepository,
characterDetailMapper = characterDetailMapper
)
} And after that depends on our propose we have the following scenarios:
class CharactersListFragment :
BaseFragment<FragmentCharactersListBinding, CharacterDetailViewModel>(// now this use the CharacterDetailViewModel
layoutId = R.layout.fragment_characters_list
)
Please let me know if this helps you |
@vmadalin Thanks a lot!) |
is it possible to inject the same veivmodel into different fragments? I mean
BaseFragment<FragmentSomeBinding, SharedViewModel>
The text was updated successfully, but these errors were encountered: