[Mobile] Question regarding the implementation of InternalNavigateToAsync and AutoWire
RedasP opened this issue · comments
In NavigationService's InternalNavigateToAsync method, I see that InitializeAsync is called after the Page instance is created. This can result in a NullReferenceException if the Page's ViewModel, which is created by AutoWire, is not initialized by InitializeAsync and Page starts binding to ViewModel's properties.
For example, this would crash:
public int OrderPrice => Order.Price;
because Order
can be initialized only when InitializeAsync is called using navigationData
Should every ViewModel be responsible for handling the possibility of uninitialized data?
For example:
public int OrderPrice => Order?.Price ?? 0;
The conditional logic could be avoided if we InitializeAsync first, before assigning BindingContext to the Page.
Hi @RedasP, Recently Xamarin mobile client app has been moved to a different repo eshop-mobile-client
So I have moved this issue to this new repo #14 for further tracking.
I am closing this issue as of now. If you face any further questions, please feel free to open a new issue in the repo eshop-mobile-client
Thank you.