473,395 Members | 1,464 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,395 software developers and data experts.

understanding Singleton

Hi,

I am a bit confused using Singleton pattern.
Using Singleton - do I have one instanse of the class for each web
client or do I have one instanse for all users ?

Thanks.

Ruthie.

Apr 10 '07 #1
6 1380
On Apr 10, 7:43 am, "ruthie" <ruthie...@yahoo.comwrote:
I am a bit confused using Singleton pattern.
Using Singleton - do I have one instanse of the class for each web
client or do I have one instanse for all users ?
It's not entirely clear what you mean. Are you writing an ASP.NET
application, or are you writing a web client?

If you're writing an ASP.NET application, there will be one for the
whole web application - but you should be aware that ASP.NET can
recycle its applications periodically, so the old one may be thrown
away and a new one created.

If you're writing a web *client*, there will be one for each process.
(More strictly speaking, for each AppDomain - but that distinction is
unlikely to be an issue.)

Jon

Apr 10 '07 #2
ruthie ha scritto:
Hi,

I am a bit confused using Singleton pattern.
The main feature of the Singleton design pattern is to have a single
instance of a class for each AppDomain (correct?).

Bye,
Giulio

--
Apr 10 '07 #3
On Apr 10, 10:08 am, Giulio Petrucci <faken...@fakedomain.comwrote:
ruthie ha scritto:
Hi,
I am a bit confused using Singleton pattern.

The main feature of the Singleton design pattern is to have a single
instance of a class for each AppDomain (correct?).

Bye,
Giulio

--
Thanks Jon & Giulio ,

You answered my question - I am developing an asp.net application
project.

Best Regards,
Ruthie.

Apr 10 '07 #4
On Apr 10, 11:43 am, "ruthie" <ruthie...@yahoo.comwrote:
Hi,

I am a bit confused using Singleton pattern.
Using Singleton - do I have one instanse of the class for each web
client or do I have one instanse for all users ?

Thanks.

Ruthie.
Hi Ruthie,

Answer to your question is: You will have One instance for all users.

Singleton pattern restricts instantiation of a class to one and only
object. hence all the requests will be served by the same instance of
class.

Check out the link: http://en.wikipedia.org/wiki/Singleton_pattern

Regards

Apr 11 '07 #5
Jon Skeet [C# MVP] wrote:
On Apr 10, 7:43 am, "ruthie" <ruthie...@yahoo.comwrote:
>I am a bit confused using Singleton pattern.
Using Singleton - do I have one instanse of the class for each web
client or do I have one instanse for all users ?
If you're writing an ASP.NET application, there will be one for the
whole web application - but you should be aware that ASP.NET can
recycle its applications periodically, so the old one may be thrown
away and a new one created.
Which raises the question: what would be the best way
to get some code executed when that happen to the object ?

Finalize ?

Arne
Apr 12 '07 #6
Arne Vajhøj <ar**@vajhoej.dkwrote:
If you're writing an ASP.NET application, there will be one for the
whole web application - but you should be aware that ASP.NET can
recycle its applications periodically, so the old one may be thrown
away and a new one created.
Which raises the question: what would be the best way
to get some code executed when that happen to the object ?

Finalize ?
I'd hook into the AppDomain.DomainUnload event, I think. I'd also try
to design things so that it wasn't necessary :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 12 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Tim Clacy | last post by:
Is there such a thing as a Singleton template that actually saves programming effort? Is it possible to actually use a template to make an arbitrary class a singleton without having to: a)...
10
by: E. Robert Tisdale | last post by:
Could somebody please help me with the definition of a singleton? > cat singleton.cc class { private: // representation int A; int B; public: //functions
1
by: Jim Strathmeyer | last post by:
So I'm trying to implement a singleton template class, but I'm getting a confusing 'undefined reference' when it tries to link. Here's the code and g++'s output. Any help? // singleton.h ...
3
by: Alicia Roberts | last post by:
Hello everyone, I have been researching the Singleton Pattern. Since the singleton pattern uses a private constructor which in turn reduces extendability, if you make the Singleton Polymorphic...
3
by: Harry | last post by:
Hi ppl I have a doubt on singleton class. I am writing a program below class singleton { private: singleton(){}; public: //way 1
5
by: Pelle Beckman | last post by:
Hi, I've done some progress in writing a rather simple singleton template. However, I need a smart way to pass constructor arguments via the template. I've been suggested reading "Modern C++...
10
by: Binary Poet | last post by:
I have a project that is a DLL which is nothing more than a VB Module with a number of public classes inside of it. From what I have read, it is possible to have this DLL be only started once. For...
3
weaknessforcats
by: weaknessforcats | last post by:
Design Pattern: The Singleton Overview Use the Singleton Design Pattern when you want to have only one instance of a class. This single instance must have a single global point of access. That...
3
by: stevewilliams2004 | last post by:
I am attempting to create a singleton, and was wondering if someone could give me a sanity check on the design - does it accomplish my constraints, and/or am I over complicating things. My design...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.