Prism navigation - how to handle child view initialisation and cleanup? -
i have "parent" view containing several regions, load other views. these "child" views same , don't change @ runtime, registered regions during application startup, using regionmanager.registerviewwithregion... syntax. views singletons, , use castle windsor ioc.
bearing in mind 'inavigationaware' methods don't called on view-models in nested regions, what's approach initialisation , cleanup of child views? "acceptable" design parent vm hold references (injected) child vm? call kind of init/cleanup methods on child vms within parent's onnavigatedto()/from() method?
another option might change views transient, use constructor initialisation, , not worry cleanup (which clear down old "state" before view re-used , displayed). potential issue application uses "event service" (similar prism's event broker), view-models acting publishers , others subscribers. i'm concerned if made them transient, view-models won't gc'd because of event subscription, , these "dead" views continue responding events. correct? if so, presumably need implement way of cleaning (as above), can unsubscribe?
i've came across same problem, while back.
the way did implement inavigationaware interface on parent viewmodel , in viewmodels of scoped regions/views , on parent viewmodel onnavigatedfrom method, call onnavigatedfrom of children viewmodels.
bear in mind have keep reference of children viewmodels in parent viewmodel (which believe not bad practice). reference can injected container , deleted (teared down) when navigate away parent view (depending on value of keepalive property if you've implemented iregionmemberlifetime in parent , children viewmodels).
Comments
Post a Comment