473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

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 1470
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: stephan beal | last post by:
Good morning, C++ users, i've been hesitating to post this, primarily because i know that most of you here are *way* ahead of me in C++ and i'm a little embarassed about the possibility of some...
11
by: Tito | last post by:
I have two questions about the singletons' chapter of Alexei Alexandrescu's "C++ Modern Design". 1. In the beginning of the chapter Alexei states that a "singleton" class implementation made of...
3
by: Dominik Rau | last post by:
Hi. I've got the following problem here: In my application, I use a lot of Singletons, that are implemented as described in Gamma et al. (shortened): //.h class Singleton{ public: static...
8
by: 6tc1 | last post by:
Hi all, I'm having a problem where in my solution that contains multiple projects - I instantiate a singleton class in one assembly and then if another assembly tries to use that singleton class...
11
by: John Fly | last post by:
I'm working on a large project(from scratch). The program is essentially a data file processor, the overall view is this: A data file is read in, validated and stored in a memory structure...
6
by: Steven Watanabe | last post by:
PEP 8 says, "Comparisons to singletons like None should always be done with 'is' or 'is not', never the equality operators." I know that "is" is an identity operator, "==" and "!=" are the equality...
6
by: =?Utf-8?B?R29yZG8=?= | last post by:
Hello everyone, I've been trying for some time now to move to C++/CLI, but I have several large legacy C++ static libraries I need to use. When I set up a simple solution with a C++/CLI Winforms...
7
by: adam.timberlake | last post by:
I was reading an article on TalkPHP (http://www.talkphp.com/ showthread.php?t=1304) about singletons but I'm afraid I don't understand why I need to use them. I understand how to code them...
12
by: Craig Allen | last post by:
Hey, forgive me for just diving in, but I have a question I was thinking of asking on another list but it really is a general question so let me ask it here. It's about how to approach making...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.