Skip to content

ViewModel constructor injection #3061

Answered by dansiegel
roubachof asked this question in .NET MAUI
Discussion options

You must be logged in to vote

So a couple of things...

  1. RegisterForNavigation actually does register the ViewModel in Prism.Maui so there is no need to do it yourself. Also it should only be registered as a transient.
  2. When you provide the View and ViewModel for Registration it provides a mapping specific to the Route... by default that would be the name of the View. However you could reuse the same View with different ViewModels based on a custom name like RegisterForNavigation<ViewA, SomeViewModel>() and RegisterForNavigation<ViewA, OtherViewModel>("ViewA1").
  3. Nothing stops you at any point from adding the ViewModel to the Constructor of the View... Prism will detect if the BindingContext is already set and will not t…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by roubachof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants