Is there any demo project using kotlin-inject and ...
# kotlin-inject
p
Is there any demo project using kotlin-inject and compose navigation? More exactly I want to scope a subcomponent to a NavGraph or to the destination which represents a NavGraph. I am not sure about the ways to know when the NavGraph destination is created and when it is destroyed. So I could create and dispose of said subcomponent respectively. I have searched but nothing related came out
My initial plan is to have a Global Map having entries with the NavGraph destination instance ID as key and the Subcomponent as value. Creating it is ok the problem is when to remove the subcomponent from the map when the NavGraph destination is gone
p
Thanks Konstantin, I will dig into it later. But judging by the name it seems this create a subcomponent tied to the ViewModel scope. But I want the Subcomponent to be tied to the NavGraph scope. That way, all ViewModels within the NavGraph will share the same dependencies instances. I plan to inject in all ViewModel a shared NavigationManager, and other shared instances. I do this right now by manually creating the instances in the NavGraphBuilder and passing the instances to the ViewModel Factories. But I feel like it can be improved by providing a custom scope, let's say NavGraphScope that will bind them automatically without manual cabling
k
just make a custom DI scope and to bind its lifecycle to what you want (you could subscribe on backstack notifications for example)
👍 1