473,385 Members | 1,838 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,385 software developers and data experts.

User & application-state variables...

I am relativly new to ASP.NET, and my question is this:

Is it better to create a wrapper class that contains all the running
settings for the application and then load that into the app state, or is it
better to load the scalar variables and store them individually?

In case I'm not making my self clear, is it better to do this:

'// Load each variable individually
Context.Cache.Add( "UserFirstName", txtFirstName.Text ... )
Context.Cache.Add( "UserLastName", txtLastName.Text ... )

or this:

'// Store vars in a class, and then cache the class
Config.ActiveUser.FirstName = txtFirstName.Text
Config.ActiveUser.LastName = txtLastName.Text

Context.Cache.Add( "Config", Config ... )

?

Thanks,
Jeremy
Nov 18 '05 #1
3 1551
Both ways are valid. It's all about tradeoffs.
The first way is simpler, the second way allows for more custom
functionality.
Simplicity vs. Power is the kind of decision we developers face nearly every
day.
You must decide which way is best for your app.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Jeremy" <th***********@hotmail.com> wrote in message
news:tF********************@twister.tampabay.rr.co m...
I am relativly new to ASP.NET, and my question is this:

Is it better to create a wrapper class that contains all the running
settings for the application and then load that into the app state, or is it better to load the scalar variables and store them individually?

In case I'm not making my self clear, is it better to do this:

'// Load each variable individually
Context.Cache.Add( "UserFirstName", txtFirstName.Text ... )
Context.Cache.Add( "UserLastName", txtLastName.Text ... )

or this:

'// Store vars in a class, and then cache the class
Config.ActiveUser.FirstName = txtFirstName.Text
Config.ActiveUser.LastName = txtLastName.Text

Context.Cache.Add( "Config", Config ... )

?

Thanks,
Jeremy

Nov 18 '05 #2
Hello Jeremy,
Is it better to create a wrapper class that contains all the running
settings for the application and then load that into the app state, or
is it better to load the scalar variables and store them individually?


My answer is going to be geared toward session, however, I think that you'll be able to apply this anywhere.

Typically, the first thing that I do when I start up a web project that requires session state is implement a wrapper class for it that looks like this:

class SessionManager
{
private const string SESSION_MANAGER = "SESSION_MANAGER";
private string username;

private SessionManager()
{
}

public string UserName
{
get { return username; }
set { username = value; }
}

public static SessionManager Instance
{
SessionManager manager = HttpContext.Current.Session[SESSION_MANAGER] as SessionManager;
if (manager == null)
{
manager = new SessionManager();
HttpContext.Current.Session[SESSION_MANAGER] = manager;
}
return manager;
}
}

Using this class is very simple. All you need to do is add property accessors to it for items that you wish to store in session, as I have done in the above example with the UserName property.

When I want to access the session state in the code, I type
SessionManager.Instance.UserName = "someValue"; or
string someValue = SessionManager.Instance.UserName;

What I have now is a singleton pattern that exposes any session state that I need in a strongly typed fashion (ie: no longer do I run the risk of accidentally typing in the wrong string when I do Session["someValue"]). I can also control whether or not a property is read only at compile time.

I hope this answers your question.

--
Matt Berther
<a href="http://www.mattberther.com">http://www.mattberther.com</a>

Nov 18 '05 #3
As another follow up -

Be careful not to put user specific information (like first and last
name) into the cache without some unique per user identifier (or
consider using the Session object). Otherwise two different users may
see the same name pulled from the cache when they come to your site.

--
Scott
http://www.OdeToCode.com

On Thu, 15 Apr 2004 15:27:29 -0700, "Steve C. Orr [MVP, MCSD]"
<St***@Orr.net> wrote:
Both ways are valid. It's all about tradeoffs.
The first way is simpler, the second way allows for more custom
functionality.
Simplicity vs. Power is the kind of decision we developers face nearly every
day.
You must decide which way is best for your app.


Nov 18 '05 #4

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

Similar topics

4
by: MLH | last post by:
A programmer developed an AMP (Apache/MySQL/PHP) application for me. When he was done, he sent me the PHP files and the MySQL dump file. Now, when I connect to the application on my LAN using...
88
by: Mike | last post by:
Is there a way to determine what a user's default email client is? I read a post from 3 years ago that said no. I guess I'm hoping something has come along since then.
4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
1
by: Nathan Alden | last post by:
I have an XSD defined as the following: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"...
4
by: Jason Shohet | last post by:
A user runs a .NET application that authenticates them against active directory (they're coming in over VPN so they don't log on to the network normally). Once they log in, I want to take their...
2
by: memHog | last post by:
I am trying to create a windows application that will perform drag and drop between a usercontrol on a toolbar and a "user document". As the user control is being dragged accross the user...
2
by: Patrick Blackman | last post by:
Hi, need some info on implementing a multiuser winforms application, specifically managing user logins and user preferences & access rights. Are there any frameworks out there for this. I don't...
0
by: WhiteWizard | last post by:
Here’s the situation: I am writing a C# Windows application using VS 2003. I have built a user control, and it has a Tab Control on it with (currently) 2 tab pages, and the whole thing sits...
0
by: sreehari | last post by:
Hi, I have a problem and dont have much clue on how to proceed with it. il try to describe the situation best below. I have a user control, and two forms which i have exported as template...
2
by: =?Utf-8?B?VW1lc2huYXRo?= | last post by:
Hi, My application is running with two web server let say W1 & W2 and load balance controls the request to web servers . One of my application page pop up a new page and there I am using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.