tags:

views:

106

answers:

4

What are the best way to store variables in a silverlight application?

Need to transfer store a customer ID throught the application but im not sure what is the best way

A: 

You may look at using InitParams, without knowing the situation I can't say much more.

http://msdn.microsoft.com/en-us/library/cc838255(VS.95).aspx

Iz
A: 

Store the variable in a place where those things that need to get to it, can; and those things that don't need to get to it, can't. Can't say anything more specific without more information.

mjfgates
Where is the best place to store these, in .net I use the global.aspx or session variables. Is there anything like this i can use in silverlight. If you have any basic examples that would be fantastic
Steven
A: 

If you were following an MVVM pattern then I would have said as a property of the Customer model, with an instance of the customer model being accessed via the ViewModel.

Even if you aren't I would say within the application code and use binding where its needed in the UI. Otherwise you run the risk of changes to your UI causing the loss of customer ID storage at somepoint in the future.

If needed in more than one place then just create a repository that stores all of your data and have that accessed as needed (this way you can decouple your UIs from each other even if they use the same data source.

ChrisBD
+1  A: 

Disclaimer: This is a purely subjective answer. Others might object or have better suggestions.


I work mostly in VB.NET and over there, we've got the My.Application namespace where we can keep global variables. VB.NET users also have the option of using a Module for such purposes.
A Module, if I remember right, is equivalent to a static sealed class in C# so you can essentially do something of that sort.

To replicate VB.NET's functionality when I work in C#, I create a static class, with access level set to internal so its members are accessible from within the entire application.
Thus, when I assign a value to a member of the static class, it is accessible from all other classes in the application.


Hope this helps

Alex Essilfie