How to use AppSettings after restore with Per Request VM approach

Aug 20, 2011 at 5:44 AM


I'm putting together a demo of the StorageHandler features of Caliburn Micro. However, what i'm noticing is that the CurrentNumber gets stored and restored propertly but if i back out of the page to another page and go back in, it resets to zero.

I can get it to work by using a Singleton approach for creating the VMs in the bootstrapper, but i've never found this performs particularly well on the phone and so have always recommended a Per Request VM model.

Just out of interest then, how easy would it be to have the state restoration work alongside a per request VM approach?

I guess it's just a case of savign the state not against the instance of the VM as it tombstomes but against it's type, and then when any instance of it is activated or whatever the state can be brought back in.

Lastly, how would one ensure that the state was saved on VM deactivation, rather than waiting for the App to tombstone, is there an API to flush changes out?

    /// <summary>
    /// Helps with tombstoning the Storage View Model
    /// </summary>
    public class StoragePageStorageWorker : StorageHandler<StorageViewModel>
        public override void Configure()
            // make sure we store the current number
            this.Property(vm => vm.CurrentNumber)