I've two commands in my View Model and one of them is initialized using lazy loading and other using eager loading.
Which approach is good to go? Should I use lazy loading or eager for both?
View Model:
public class LoginPageViewModel : MvxViewModel
{
public LoginPageViewModel()
{
InitializeCommands();
}
public MvxCommand<object> LoginCommand { get; set; }
private MvxCommand<object> signUpCommand;
public MvxCommand<object> SignUpCommand
{
get
{
return signUpCommand ?? (signUpCommand = new MvxCommand<object>(o => {
ShowViewModel<SignupPageViewModel> ();
}));
}
}
private void InitializeCommands()
{
LoginCommand = new MvxCommand<object>(LoginUser);
}
}
View:
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
var set = this.CreateBindingSet<LoginPageView, LoginPageViewModel> ();
set.Bind (CreateAccountButton).To (vm => vm.SignUpCommand);
set.Bind (ResetPasswordButton).To (vm => vm.ResetPasswordCommand);
set.Apply ();
}
I'm using that within iOS app developed using Xamrian.iOS and MVVMCross
DoSomething
to run? Is the initialisation computationally expensive? Does it use external resources? How likely is it thatMyCommand
will never be accessed for an instance? Etc, etc. There's no one right way to do it, it depends on the context.