472,806 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,806 software developers and data experts.

global object variable


I have a design problem involving class instances as global variables. To give you my background, I've programmed lots in Java, and most of it has been large class structures. I'm learning c# the hard way, but the similarities to Java are very helpful. However, in this case they are hurting, because I can't figure out the best way to store a class that can be accessed across the scope of an ASP.NET application.

To begin with, there are three types of users to my site - people viewing my site (WebUsers), people operating my site (Operators), and both operators and WebUsers are stored as the third type. A list of WebUsers is stored as a dictionary in a CustomerObserver class, and a dictionary of Operators is stored in an OperatorManager class. All the users are stored in a dictionary in the UserManager class. Finally, an instance of each of those three classes is stored in a Client class, and all the Clients are stored in a ClientManager class. This ClientManager is the one and only instance that will be allowed, application-wide. I'm trying to make this ClientManager accessible to all pages and classes, but have run into problem with both methods I've tried.

1) I initially kept all the function and members of these classes static, so that they could be accessible with just the class name. For example, I could get any WebUser object from anywhere with CustomerObserver.WebUser[UserID]. However, the scope of these static instances lasted only as long as the page I was viewing existed. As an example, if you viewed page1.aspx, the page would create a WebUser object for you and save it in the CustomerObserver's dictionary of WebUsers. However, when you visit page2.aspx and tried to access the WebUser dictionary, the WebUser object created in page1 has now disappeared.

2) I now have the ClientManager stored as an application variable, Application["ClientManager"]. It can be accessed by any page, but we run into problems in two ways. First, there's no "pretty and easy" way to access it quickly (such as CustomerObserver.WebUser[UserID] above), and only pages, not classes, can access it. So, each page that accesses some functionality of ClientManager must retrieve the application variable, pass it along to the class that needs it, perform any functionality that requires any member or sub-member of ClientManager, and then store the ClientManager back in the Application variable, in case it changed. Not only is this clunky, but it is also not thread-safe, so each time ClientManager is accessed it must lock the application until ClientManager is stored again. Scalability with this design is impossible.

Is there any way to have a global object variable accessible across an application?

Message posted via http://www.dotnetmonster.com
Jul 21 '05 #1
0 1394

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Matt | last post by:
Greetings, What are people's thoughts on global variables in C++? Why are we taught not to use them in programming? Is it true that if you are running two copies of the C program one copy can...
by: Andrew V. Romero | last post by:
I have been working on a function which makes it easier for me to pull variables from the URL. So far I have: <script language="JavaScript"> var variablesInUrl; var vArray = new Array(); ...
by: Richard A. DeVenezia | last post by:
Dear Experts: Suppose I have global variables: x1, x2, x3 and I have a function that needs to assign a value to a new global variable x4 something like function foo () { count = 0;
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined...
by: Miguel Dias Moura | last post by:
Hello, I am working on an ASP.NET / VB page and I created a variable "query": Sub Page_Load(sender As Object, e As System.EventArgs) Dim query as String = String.Empty ... query =...
by: Shapper | last post by:
Hello, I am declaring a variable in my aspx.vb code as follows: Public Class catalogue Public productid As String Private Sub Page_Load ... I have an image button where I call the...
by: Roman Ziak | last post by:
Hello, there were times when I used to be looking for a way to access JavaScript Global object similar to those found in VBScript or PHP ($GLOBALS). At present this has only academic value for...
by: User1014 | last post by:
A global variable is really just a property of the "Global Object", so what does that make a function defined in the global context? A method of the Global Object? ...
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: lllomh | last post by:
How does React native implement an English player?
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.