I've got a bunch of Silverlight 5 applications hosted in a website that set some application specific data. One of these datum is a CurrentUser object.
On startup of any of the apps, they talk to a web service to pull in the current user information. However, this needs to be accessed from all sorts of places in the SL application.
I thought it made sense to put it on the Application object itself, but I wasn't sure if this was a good practice.
I put a simple property containing the user in an interface and implemented it on the main application class.
Then, the rest of the application code accesses it via a static class:
Public Module ApplicationUtils Public Property CurrentUser() As WebUser Get Dim app As ICommonAppData = TryCast(Application.Current, ICommonAppData) If (app IsNot Nothing) Then Return app.CurrentUser End If Return Nothing End Get Set(value As WebUser) Dim app As ICommonAppData = TryCast(Application.Current, ICommonAppData) If (app IsNot Nothing) Then app.CurrentUser = value End If Throw New NotImplementedException("Current application does not implement required interface") End Set End Property End Module
I'm trying to find out if this is an accepted practice to access global data, or if there is a complication I'm not realizing here (thread safety issues, etc.). If this is not the right place to store app global data (or perhaps even just user data), where do we put it in a Silverlight project? I had heard that perhaps I needed elevated permissions/trust in order to access Application.Current like this, so is this the case as well?