Public Variables

G

Guest

I am developing 3-tiered application. I have and ASP UI, VB.Net Business
Objects and a SQL ServerDB.

I am encountering a problem that I have a mental block on and would
appreciate some help.

When the user logs on and moves around the application, there is data that
is required by any business object that is instantiated in the Business
layer. An example of this data is UserID (I have about 15 other values that
I want to keep track of)

What I have tried is to have a class called clsAppData that contains all of
the values that I'm interested in:

Public Class clsAppData
Public UserID as Integer

Public Shared Function GetAppData as clsAppData
Return AppData
End Function
End Class

I then have a public variable declared in a module in my business layer
which is visible to all other objects in this layer:

Public Module modGlobals
Friend AppData as clsAppData
End Module




This works fine if only one session is active. If I have more than one
session, the AppData variable seems to be visible accross sessions. This is
not the behaviour I want. What I want is a variable that is visible to all
objects in my business layer, but only within the context of the ASP Session.

Could someone help me with this


tia

Terry Holland
 
M

Mythran

Terry Holland said:
I am developing 3-tiered application. I have and ASP UI, VB.Net Business
Objects and a SQL ServerDB.

I am encountering a problem that I have a mental block on and would
appreciate some help.

When the user logs on and moves around the application, there is data that
is required by any business object that is instantiated in the Business
layer. An example of this data is UserID (I have about 15 other values
that
I want to keep track of)

What I have tried is to have a class called clsAppData that contains all
of
the values that I'm interested in:

Public Class clsAppData
Public UserID as Integer

Public Shared Function GetAppData as clsAppData
Return AppData
End Function
End Class

I then have a public variable declared in a module in my business layer
which is visible to all other objects in this layer:

Public Module modGlobals
Friend AppData as clsAppData
End Module




This works fine if only one session is active. If I have more than one
session, the AppData variable seems to be visible accross sessions. This
is
not the behaviour I want. What I want is a variable that is visible to
all
objects in my business layer, but only within the context of the ASP
Session.

Could someone help me with this


tia

Terry Holland

I can't imagine needing that much information across all business layers
but, one solution (and probably not the best solution) would be to create a
class that implements the IIdentity object and place all that extra
information within properties of the derived class. The identity class
isn't really meant for this, but it's one way to do it. The Identity class
can then be passed to the Principal object (as part of it's constructor) and
the Principal can be attached to the Thread currently running. Then you can
access the Identity object through the Principal object through the Thread
object throughout all of your tiers (as long as all tiers are running on the
same thread on the same machine).

HTH,
Mythran
 
K

KJ

One easy (and perhaps naive) way to achieve this is to put your instance of
the special class in the Session, then, have your BL objects access it from
HttpContext.Current.Session
 
G

Guest

Correct me if I'm wrong but if you put this stuff in a Module in VB.NET then
its Shared (static). You need to put it in a class. Also, you might want to
look into Membership / Profile providers as the Profile is what this kind of
stuff was designed for.
Peter
 
J

John Saunders [MVP]

Terry Holland said:
I am developing 3-tiered application. I have and ASP UI, VB.Net Business
Objects and a SQL ServerDB.
....
I then have a public variable declared in a module in my business layer
which is visible to all other objects in this layer:

Public Module modGlobals
Friend AppData as clsAppData
End Module

You want to stop using modules in ASP.NET applications. You have found out
the easy way that the data in that module is shared across all sessions.
What you have not yet learned is that this requires locking if the data are
ever going to change.

You don't want to find that out the hard way, so stop using modules. They're
a holdover from VB6 days and have no place in object-oriented development.
 
G

Guest

Thanks guys

Ive changed the way I do things so that Im passing necessary parameters to
my bo layer on each request
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top