Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Tight coupling view/viewmodels through routes #41

Open
ronaldvdv opened this issue Aug 23, 2023 · 4 comments
Open

Tight coupling view/viewmodels through routes #41

ronaldvdv opened this issue Aug 23, 2023 · 4 comments

Comments

@ronaldvdv
Copy link

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 the AppShell which I would consider to be part of the view layer.

@jamesmontemagno
Copy link
Collaborator

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?

@ronaldvdv
Copy link
Author

(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?

@jamesmontemagno
Copy link
Collaborator

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?

@jamesmontemagno
Copy link
Collaborator

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants