understanding Singleton

  • Thread starter Thread starter ruthie
  • Start date Start date
R

ruthie

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

--
 
ruthie ha scritto:



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.
 
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
 
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
 
Arne Vajhøj said:
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 :)
 
Back
Top