https://kotlinlang.org logo
#dagger
Title
# dagger
c

Constantin Cezar Begu

01/23/2023, 3:30 PM
Hey I have a interesting problem. I am using hilt right now and found a limitation. Basically I want to. scope a class to a viewmodel store owner. Generally people would say to scope it to @ActivityRetainedScope but this is not good for my use case. Example: You have fragment 1 inside of fragment 2 and fragment 3 inside of fragment 2. fragment 1 and 3 can be destroyed at any point. the items created for fragment 1 (which is a viewmodel store owner) I don't want to share with fragment 2 or 3 (which are other viewmodel store owners). Injected items are shared for viewmodels (for fragment 1). Looks like @ActivityRetained scope does not do the trick since it would share for viewmodels but also for viewmodels used in fragment 1,2,3 (they use the same activity). @ViewmodelScoped scoped the item to a specific viewmodel (does not share with other viewmodels in fragment 1) Is there a elegant way to solve a problem like this?
3 Views