Persisting shell settings and application shutdown

Topics: Prism v2 - WPF 3.5
Aug 11, 2009 at 1:33 AM

I am just learning about Prism and the design pattern for composing loosely coupled apps...What a learning curve!  I have been looking at lots of examples but have not seen anything regarding a mechanism persisting "session" values prior to application shutdown.  I put the word session in quotes because at this point I am only interested in WPF and session usually connotes a web app.  I would like to be able to query all the presenters to a) determine if it is OK to shutdown, and b) if they have data to be persisted.  Does anyone know of a pattern that solves this?



Aug 11, 2009 at 1:10 PM

Hi rickburke133,  "What a learning curve!" - I feel (remember) your pain...

I would use a combination of the a) Chain of responsibility and b) Memento patterns using isolated storage to meet your requirements. 

Aug 16, 2009 at 1:01 PM


Thanks for your reply!

I decided that for my current app the presenters did not need to respond back to the requestor to prevent shutdown, they just needed to persist their state at the right time. The solution that I came up with is to create a global CompositeCommand that the presenters can add a "SaveSettings" command to.  I created a persistence service that manages de/serialization with an IsolatedStorage file and that caches the settings. Now shutdown works, and the presenters are saving their state.

I have two problems now.  1)  I am firing the composite command from a Closing handler in the Shell codebehind.  I would like to move it out of there, but haven't figured out how to bind the Closing event to the presenter from XAML.  2) There is a problem with sequencing startup.  Running in the debugger without breakpoints, the app comes up OK, using the settings values as loaded from the IsolatedStorage.  However when I run without debugging, my call to GetUserStoreForApplication() throws an exception...Unable to determine application identity of the caller.

Anyway, thanks again for the consult!