4

I have a Silverlight app that always needs to know what Customer (domain object) is currently loaded. There can only be one loaded at a time. If the Customer is null, no Customer is loaded currently. Or you exited a Customer. I'm going to have 3 more state-type properties like Customer. So...

What is the best way to store application state in a Silverlight application?

1) add public properties to the App class (App.xaml.cs)
2) have a state object that you can new up as a singleton via your IoC container. add public properties to this object 3) any other ideas?

BuddyJoe
  • 69,735
  • 114
  • 291
  • 466

3 Answers3

1

My vote would be for your second option, to have a state object singleton. If you are using MVVM and the Silverlight Toolkit, then you would have one built right into your MainViewModel which is static and statically initialized in the ViewModelLocator. That would be a perfect place to accomplish your desired result.

t3rse
  • 10,024
  • 11
  • 57
  • 84
1

I would go for the second option.

Currently working on a Silverlight application that stores state data of domain objects.

We have what has been termed an ApplicationManager that is resolved via IoC to store reference data and domain data. There might be a better term than ApplicationManager, but to date have not found a standard naming convention.

The concept works well, all of our View Models have access to the ApplicationManager, so all we pass around is entity id's when another part of the application needs to take action.

If you have asynch operations updating the data you need to be mindful of keeping the UI and data store consistent

Adrian Russell
  • 3,995
  • 5
  • 25
  • 26
1

I had a similar problem. As I am using MEF, I created a service which holds the data. The you can import the service where you need it and have access to the referenced objects. (So it is similar to 2)

TerenceJackson
  • 1,776
  • 15
  • 24
  • How does the service "hold the data"? Or did you mean the services stores and retrieves the data? – BuddyJoe Nov 17 '10 at 14:21
  • You could do both. So the service is responsible for getting the data and it has a property where the currently loaded customer is stored (That was what I meant by "holding the data") – TerenceJackson Nov 17 '10 at 15:23