Auto Binding of ViewModel to View BindingContext #517
Replies: 4 comments 3 replies
-
@rjygraham I didn't read all your spec yet, but a friendly reminder that .NET MAUI exposes the |
Beta Was this translation helpful? Give feedback.
-
Thanks Ryan!! This looks very promising! Could you also add include some benchmarks? I'm curious how |
Beta Was this translation helpful? Give feedback.
-
One note - To support Dependency Injection, we'll want to avoid How does .NET MAUI do this internally? Maybe we can leverage some of their existing services to ensure we don't break Dependency Injection for folks! |
Beta Was this translation helpful? Give feedback.
-
Closed as per the Community Stand-up discussion here: https://youtu.be/N9wMcBP4jtg?t=2889 |
Beta Was this translation helpful? Give feedback.
-
Now that the
ServiceCollectionExtensions
methods for registering Views and ViewModels has been released, I've been thinking about how we can automatically bind the ViewModel to the View'sBindingContext
.The solution for Views and ViewModels registered via one of the
AddxxxxxxWithShellRoute()
methods is fairly straightforward using the following RouteFactory implementation:With this in place, we can modify the
RegisterShellRoute
method ofServiceCollectionExtensions
from this:to this:
Unfortunately, I believe we'd need changes to .NET MAUI proper to handle this for implicitly registered Shell routes, applications using non-Shell routing, and other Views.
Implementing this for explicit Shell routing while not having a solution for the other scenarios would likely lead to a confusing developer experience; however, I wanted to at least get the conversation started in case someone in the community has ideas on how we can make this work.
From my perspective, auto-binding for implicit and explicit Shell routes is the minimum viable product.
Beta Was this translation helpful? Give feedback.
All reactions