Singletons in ASP.NET 2.0

O

Omega

I'm interested in seeing a bit of discussion about using singletons in
ASP.NET 2.0.

Currently I've designed a singleton that gets a reference to it's
single instance stored inside the ASP.NET application object. This is
done to persist and make available live information across multiple
sessions.

I've read a little bit (almost nothing) about how singletons don't play
nicely in clustered scenarios and would like to hear more on the
subject.

As mentioned above, my class is only a singleton because it's only
reference is stored in the application object. Because of this, I
could just as easily NOT write singleton and simply instantiate the
same object in the same place as where I'm storing the reference
(application handler on application start).
From what I can see, the application object is the only place ASP.NET
makes available a facility to put code that lives throughout the
application.

How does clustering really impact a singleton or a single instance of a
class stored in the application object?
 
B

bruce barker \(sqlwork.com\)

the impact of a cluster on a singleton depends on the functionality of the
singleton. if the singleton is a cache of read only data, then there is
none. if the singleton is a cache of realtime data coming from the web site,
then there is.

say you singleton was a counter of logged in users implemented as a static
counter. a version of the counter would exist on each cluster member, and
updating one has no effect on the others. you would then have to write code
so that the singltons updated each other.

any class can implement the singleton pattern thru the static (shaed in vb)
methods or properties.

-- bruce (sqlwork.com)
 
K

Karl Seguin [MVP]

Application state is per-worker process. Which means a cluster of 2 or more
servers will each have their own application state. This means you can't
have true singletons by using the Application object. If you need a true
singleton, you need to find a way to share it across each server. A
somewhat complicated but highly efficient way is to use .NET Remoting.

Karl
 
O

Omega

VERY informative from both of you. Thank you.

Understanding more how the pages work as a process on the system
certainly paints a clearer picture.

Having not read a book on running ASP.NET 2.0 sites, I can't really
make any guesses on how it would behave.

Can either of you reccomend a book that covers the insides & outs of
the MS application server? I'm interested in learning every little
detail to ensure that my programs are well tuned.
 
O

Omega

I find that online searches don't always result in the structure and
focus needed to cover something with as many facets as IIS & ASP.NET
2.0 administration. Looking at the snap-in, I can see many things that
could be done great justice with some explanation.
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top