Static Class Factory - Alice is seeing Bob's data

G

Guest

Morning,

I've got an ASP.NET 2.0 Web Application. Behind it, I've a
statically-scoped facade/class factory as the business layer, running atomic
functions back and forth from my by DAL.

The DAL returns DataSet objects to the facade, which loads the data into a
memento object to pass to the ASP.NET interface.

For instance, I've got the method Profile ProfileSystem.GetProfile(Guid
userID) which will take the user's GUID as an input and return me the Profile
memento class for use in interface. The memento class has no real
functionality, it is just a representation of an object which can be used
safely either in my app or through a public web service.

I use these memento objects to create a PNG image. This is working very
well, and I've got four different designs.

However, occasionally, one user's image will contain a different user's
data. I can see that this isn't a image cacheing issue (as I thought at
first) because these two users will be using different image types. Where I
would expect to see the first user's (Alice) image and data, I see Alice's
image with Bob's data in it. I know it isn't Bob's image because he has a
different type of image. The request to class factory with Alice's Guid has
returned Bob's data (AFAICT).

Have I royally messed up my architecture here?
 
P

Patrice

Static data are shared accross the whole application domain. As a web site
is a single application, it means that static data are shared accross all
users. This is mot often the problem (you still can use static properties as
long as the underlying storage is not shared).

--
Patrice

"(e-mail address removed)" <[email protected]>
a écrit dans le message de
(e-mail address removed)...
 
M

Mark Rae [MVP]

Have I royally messed up my architecture here?

Static variables in ASP.NET need *extremely* careful management because they
persist across all Sessions. That's almost certainly what you're seeing
here...
 
G

Guest

Thanks for the replys - I've read the article Patrice recommended.

I understand that using static objects can have issues with shared values e.g.

static class TempStore
{

int myValue;

static TempStore()
{}

static Int GetValue()
{
return myValue;
}

static SetValue(int inpVal)
{
myValue = inpVal;
}
}
}

I can see that this would be bad as users will continuously be overwriting
each others values, but I don't see why this would be for a static class
factory

static class ClassFactory
{
static ClassFactory()
{}

static ProfileData GetProfile(Guid userID)
{
....Load DAL
....Get data
....Return data
}
}


Why would the GetProfile method above return the wrong data to the user?

Thanks
 
B

bruce barker

you are confusing static methods with static objects. your factory
sample is a static method. this method is thread/session safe as long as
it and all of the method calls made do not use a static object. In your
case one of them must (there must be code that looks like you first
example).

-- bruce (sqlwork.com)
 
P

Patrice

This is not necessarily in this class. You'll have to check for input and
output values (if the argument or the result is at some point stored in a
static value it could cause the same problem). You could have also the same
problem somewhere in your "get data" code.

--
Patrice

"(e-mail address removed)" <[email protected]>
a écrit dans le message de
(e-mail address removed)...
 

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,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top