How to handle UI interaction from view model without user request using MVVM, PRISM, and MEF -
i working on application using wpf, mvvm, prism, , mef.
i using combination of navigation request navigate, controllers view management using region manager, , eventing via event aggregator run application in single window. i'm using view first approach similar how stock trader ri works. works great when view model code interact ui (busy indicator) kicked off user, when started behind scenes there can problems.
i know may seem poor implementation, think have valid scenario. particular example has login.
currently application starts , loads shell. login view loaded main content region of shell. when user clicks "login" busy indicator shown , client application services login executed. when login complete, busy indicator goes away, , screen navigated user's home screen.
this works because navigation login , navigation initiated user clicking login button.
so have new requirement user can select auto login on login form, such next time user starts app, login view not show , login happen behind scenes.
now if want call auto login feature, there no problem, has no ui interaction , work fine. login takes few seconds , want display busy indicator.
the problem initiate auto login call? shell view model constructor? shell view model partimportssatisfied implementation? in of these places, shell view (which contains busy indicator) isn't loaded yet. result, none of resources need, regions , region managers aren’t available. might way me implement this:
check if previous user should auto login (got part figured out)
if yes show busy indicator attempt auto login if auto login success hide busy indicator navigate user home screen else hide busy indicator navigate login screen else hide busy indicator navigate login screen
any ideas appreciated.
implement interface within shellviewmodel
deal concept of being loadable. not perform logic within constructor of shellviewmodel
typically bad practice , should used instantiate objects @ most.
public class shellviewmodel : iloadable { public shellviewmodel() { } bool iloadable.load() { //this can take care of auto login } }
you call within bootstrapper
class. if being done within module call within imodule.initialize
method.
i argue logic should implemented within service called shellviewmodel
mentioned above or in theory called directly bootstrapper
class; allowing shellviewmodel potentially make use of stateful data within service.
Comments
Post a Comment