Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Static Class Factory - Alice is seeing Bob's data

0 views
Skip to first unread message

rivalnewsg...@discussions.microsoft.com

unread,
Oct 11, 2007, 4:53:00 AM10/11/07
to
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?

Patrice

unread,
Oct 11, 2007, 6:57:00 AM10/11/07
to
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

"ri...@newsgroups.nospam" <rivalnewsg...@discussions.microsoft.com>
a écrit dans le message de news:
2CE233A8-8B05-4688...@microsoft.com...

Patrice

unread,
Oct 11, 2007, 6:58:22 AM10/11/07
to
You may want to check http://support.microsoft.com/kb/893666/en-us for
details.

"Patrice" <http://www.chez.com/scribe/> a écrit dans le message de news:
updJ1V$CIHA...@TK2MSFTNGP04.phx.gbl...

Mark Rae [MVP]

unread,
Oct 11, 2007, 7:34:40 AM10/11/07
to
"ri...@newsgroups.nospam" <rivalnewsg...@discussions.microsoft.com>
wrote in message news:2CE233A8-8B05-4688...@microsoft.com...

> 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...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

rivalnewsg...@discussions.microsoft.com

unread,
Oct 11, 2007, 8:29:03 AM10/11/07
to
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

bruce barker

unread,
Oct 11, 2007, 11:20:39 AM10/11/07
to
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)

Patrice

unread,
Oct 11, 2007, 11:44:29 AM10/11/07
to
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

"ri...@newsgroups.nospam" <rivalnewsg...@discussions.microsoft.com>
a écrit dans le message de news:

B1E89299-6753-4F82...@microsoft.com...

0 new messages