469,572 Members | 1,307 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,572 developers. It's quick & easy.

Singletons in ASP.NET 2.0

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?

May 11 '06 #1
5 1345
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)

"Omega" <at******@gmail.com> wrote in message
news:11**********************@q12g2000cwa.googlegr oups.com...
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?

May 11 '06 #2
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

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Omega" <at******@gmail.com> wrote in message
news:11**********************@q12g2000cwa.googlegr oups.com...
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?

May 11 '06 #3
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.

May 11 '06 #4
Best online Searchable book is Google, but stay away from Booble

SA
"Omega" <at******@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
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.

May 11 '06 #5
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.

May 15 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by stephan beal | last post: by
11 posts views Thread by Tito | last post: by
3 posts views Thread by Dominik Rau | last post: by
6 posts views Thread by Steven Watanabe | last post: by
7 posts views Thread by adam.timberlake | last post: by
12 posts views Thread by Craig Allen | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.