-
Notifications
You must be signed in to change notification settings - Fork 207
Tight coupling view/viewmodels through routes #41
Comments
The routes are defined in AppShell due to how app shell works and is defining how the routes map to pages for the app itself. Another app could re-use the views and then map routes different tecnically... One way to improve this would be to have a constants file for the routes and not make them magical strings. Thoughts? |
(Thinking out loud here) It would look cleaner but basically hides the issue - the view model layer would define what routes/views can exist. Honestly I don't have a good solution in mind, am struggling at a conceptual level to figure out what would be the clean way of doing this. It seems one way or another, the view model has a dependency on the existence of a particular view for it to be able to perform its job. On the other hand, it also depends on a navigation service. The difference is that for that dependency we can use interfaces and dependency injection while for the dependency on a particular view we can't. Should the navigation service have methods for specific views? |
Yeah, it is probably something similar to : https://codemilltech.com/xamarin-forms-viewmodel-first-navigation-library/ However, a view needs a viewmodel and views are navigated between. Viewmodels should be testable separate pretty much and then the navigation service is testable... Someone has to know about something at sometime? |
Now all that being said Prism does offer up an opinionated extremely abstracted way of building apps and builds things like this into the process if something like taht is needed. |
It seems there's still a dependency of the view models on the views: When the view models call
INavigationService.NavigateToAsync()
, they pass the route key. However these route keys are defined in theAppShell
which I would consider to be part of the view layer.The text was updated successfully, but these errors were encountered: