Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Singletons in ASP.NET 2.0

 
Thread Tools Search this Thread
Old 05-11-2006, 04:47 PM   #1
Default 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?



Omega
  Reply With Quote
Old 05-11-2006, 04:58 PM   #2
bruce barker \(sqlwork.com\)
 
Posts: n/a
Default Re: Singletons in ASP.NET 2.0
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" <> wrote in message
news: 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?
>





bruce barker \(sqlwork.com\)
  Reply With Quote
Old 05-11-2006, 05:00 PM   #3
Karl Seguin [MVP]
 
Posts: n/a
Default Re: Singletons in ASP.NET 2.0
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" <> wrote in message
news: 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?
>





Karl Seguin [MVP]
  Reply With Quote
Old 05-11-2006, 09:18 PM   #4
Omega
 
Posts: n/a
Default Re: Singletons in ASP.NET 2.0
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.



Omega
  Reply With Quote
Old 05-12-2006, 12:25 AM   #5
MSDN
 
Posts: n/a
Default Re: Singletons in ASP.NET 2.0
Best online Searchable book is Google, but stay away from Booble

SA


"Omega" <> wrote in message
news: 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.
>





MSDN
  Reply With Quote
Old 05-15-2006, 09:11 PM   #6
Omega
 
Posts: n/a
Default Re: Singletons in ASP.NET 2.0
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.



Omega
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
viewstate MAC failed in asp.net 2.0 while postback the page azraffarveen Software 0 05-12-2009 03:24 PM
.NET 2.0 Web Apps / .NET 3.5 ASP.NET Apps - Differences/Similariti london1919 MCTS 1 12-08-2008 03:16 PM
ASP.NET: Asign Users in Roles(Array.IndexOf(Of String) method) msandlana Software 0 04-25-2008 06:37 AM
session from asp to asp.net imman General Help Related Topics 0 02-20-2008 06:27 PM
ASP.NET 2.0 application does not run in WIN2k3 johnfraj Software 0 04-19-2007 08:27 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46