Simplify MvxFluentBindingDescriptionSet creation.
The current binding set creation:
class SomeView : MvxViewController<SomeViewModel>
{
public override void ViewDidLoad()
{
base.ViewDidLoad();
var set = this.CreateBindingSet<SomeView, SomeViewModel>();
set.Apply();
}
}
Could be simplified for Views that inherited from base View classes with generic View Model argument:
class SomeView : MvxViewController<SomeViewModel>
{
public override void ViewDidLoad()
{
base.ViewDidLoad();
var set = CreateBindingSet();
set.Apply();
}
}
With an additional method in base View class, like:
class MvxViewController<TViewModel> : MvxViewController, IMvxIosView<TViewModel> where TViewModel : class, IMvxViewModel
{
protected MvxFluentBindingDescriptionSet<MvxViewController<TViewModel>, TViewModel> CreateBindingSet()
{
return new MvxFluentBindingDescriptionSet<MvxViewController<TViewModel>, TViewModel>(this);
}
}
You are welcome to open a PR adding this.
Should CreateBindingSet() extend IMvxIosView rather than MvxViewController?
protected MvxFluentBindingDescriptionSet<IMvxIosView<TViewModel>, TViewModel> CreateBindingSet()
{
return new MvxFluentBindingDescriptionSet<IMvxIosView<TViewModel>, TViewModel>(this);
}
IMvxIosView also inherits from IMvxBindingContextOwner, so i think the above should work in the same way
Not all the MvxControllers inherit off MvxViewController. For example MvxBaseSplitViewController
Another good reason to extend IMvxView<TViewModel>: this forces us to add this new method to each implementing view, so will not forget any of them. I will prepare a PR.
@Prin53 do you mean IMvxView<TViewModel> or IMvxIosView<TViewModel>
I don't think there is any need to extend IMvxView?
@FinHorsley the first one, as there are people who using these fluent bindings on different platforms (at least on Android). If “bindings” is not a concern of this base interface we can extend base platform interfaces, like IMvxIosView<T>, IMvxAndroidView<T> and so on. What do you think?
Use IMvxView<TViewModel>. Fluent bindings are not only for iOS.
We can extend IMvxPlatformView<T> only, as we need IMvxBindingContextOwner implementation.
Why was this not implemented in IMvxView<TViewModel>?
Just asking out of curiosity.
@MarLoe see my comment above: we need IMvxBindingContextOwner to create a binding set.