Singleton instance of ViewModels?

ApurvaGoyalApurvaGoyal USMember ✭✭
edited April 2015 in Xamarin.Forms

I have many activities (forms) in my app. All these views are connected to their view-models using following code-

ViewFactory.Register<LocationView,LocationViewModel> ();

If I have a main menu from where user can navigate to Screen A or B. Navigating to Screen A creates a new instance of Screen A view model based on the code above. However when I navigate back to main menu and navigate to screen A again, will a new instance gets created again? This will cause so many instances of Screen A in the app. I am noticing crashes randomly when navigating in my app.

Can I register singleton with ViewFactory to avoid this problem? Or does ViewFactory always uses same instance whenenver I navigate to a view model?



Sign In or Register to comment.