-
Notifications
You must be signed in to change notification settings - Fork 50
Cascading BindingContext #53
Comments
One way is to register the view models as Scoped, which is generally not a good idea because it forces all the component instances of the same type to share a single view model instance. One possible approach is make the |
Sounds good to me, would love to see a PR with this. Otherwise, I'm gonna implement this. |
Right now I'm playing with this idea, but it raises some questions:
|
As of now, the
I would argue against the possibility to change the binding context since it would open some potential loop holes. The binding context should be read only once set. |
If I'm not mistaken, the view model is set right in the constructor, so it's always present.
For example WPF allows you to change DataContext, you can even bind something to it. But I agree it's not a must-have and for simplicity it's a reasonable design choice to not allow changing the view model. |
This only applies for the internal constructor that is used for testing. This constructor serves no purpose besides that. When inheriting from
It would be a nice to have thingie, however upon changing the |
Right, I misread the code. So yeah, I agree for now making |
Is there a way to have cascading BindingContext?
Say we have two components:
Now I would like to bind the BindingContext of the
Child
component in the ParentComponent to theChild
property of the ParentViewModel instance, which is automatically resolved for the ParentComponent. However it seems the view model is always resolved in the component's constructor via DI, and we don't have a publicBindingContext
property to override.The text was updated successfully, but these errors were encountered: