473,394 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

global object variable

Hello,

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 1428

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

Similar topics

10
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...
4
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(); ...
5
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;
8
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...
41
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 =...
9
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...
16
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...
3
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? ...
1
weaknessforcats
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...
112
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.