Singletons in ASP.NET 2.0

Discussion in 'ASP .Net' started by Omega, May 11, 2006.

  1. Omega

    Omega Guest

    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, May 11, 2006
    #1
    1. Advertising

  2. 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:...
    > 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\), May 11, 2006
    #2
    1. Advertising

  3. 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:...
    > 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], May 11, 2006
    #3
  4. Omega

    Omega Guest

    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, May 11, 2006
    #4
  5. Omega

    MSDN Guest

    Best online Searchable book is Google, but stay away from Booble

    SA


    "Omega" <> wrote in message
    news:...
    > 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, May 12, 2006
    #5
  6. Omega

    Omega Guest

    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, May 15, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yevgeny Menaker

    C++ singletons and .NET AppDomains

    Yevgeny Menaker, Jan 10, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    313
    Yevgeny Menaker
    Jan 10, 2004
  2. Yevgeny Menaker

    C++ singletons and .NET AppDomains

    Yevgeny Menaker, Jan 10, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    280
    Yevgeny Menaker
    Jan 10, 2004
  3. Yevgeny Menaker

    C++ singletons and .NET AppDomains

    Yevgeny Menaker, Jan 10, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,925
    Alvin Bruney
    Jan 17, 2004
  4. Soefara
    Replies:
    4
    Views:
    693
    John C. Bollinger
    Nov 18, 2003
  5. PokerMan

    Singletons in asp

    PokerMan, Mar 19, 2007, in forum: ASP .Net
    Replies:
    7
    Views:
    324
    bruce barker
    Mar 19, 2007
Loading...

Share This Page