Monday, March 26, 2012

singleton in an aspx app?

Suppose I want to supply a singleton class object that will sit between my
intranet asp.net app and MS SQL database, doing al the chemistry with
connections etc inside of it.
The problem is that I don't really know how to keep the object persistent
for all the requests nade within the app.
I need the object to live for certain periods of time, and I need it to be
easily accessible from aspx.cs files' code.
I guess I will be creating it in global.asax on application start; where do
I store it then? How do I address it?Store it in the Application Context...
Reference it through the application context.
"Sergei Shelukhin" <raven_at@.home.domonet.ru> wrote in message
news:2t2kc8F1pmmi7U1@.uni-berlin.de...
> Suppose I want to supply a singleton class object that will sit between my
> intranet asp.net app and MS SQL database, doing al the chemistry with
> connections etc inside of it.
> The problem is that I don't really know how to keep the object persistent
> for all the requests nade within the app.
> I need the object to live for certain periods of time, and I need it to be
> easily accessible from aspx.cs files' code.
> I guess I will be creating it in global.asax on application start; where
do
> I store it then? How do I address it?
>
"Sergei Shelukhin" <raven_at@.home.domonet.ru> wrote in
news:2t2kc8F1pmmi7U1@.uni-berlin.de:

> Suppose I want to supply a singleton class object that will sit
> between my intranet asp.net app and MS SQL database, doing al the
> chemistry with connections etc inside of it.
Microsoft already has a set of classes which do this: Microsoft appplicaion
data blocks (you can download the classes from MSDN). Unless you're doing
something special, it's usually not a good idea to use a singleton
structure in ASP.NET.
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
[url]http://members.ebay.com/aboutme/spot18/[/url]
Or in the "Cache" if that singleton can be weakly referenced. The only
difference between Cache and Application objects is that Application ones
are guarenteed to be there whenever you ask and Cached ones, you will need
to verify that they exist before using them.
Just another suggestion.
Girish Bharadwaj
http://msmvps.com/gbvb
"CJ Taylor" <[cege] at [tavayn] dit commmmm> wrote in message
news:ugYLvgJsEHA.1164@.TK2MSFTNGP10.phx.gbl...
> Store it in the Application Context...
> Reference it through the application context.
>
> "Sergei Shelukhin" <raven_at@.home.domonet.ru> wrote in message
> news:2t2kc8F1pmmi7U1@.uni-berlin.de...
my
persistent
be
> do
>
Sergei Shelukhin wrote:
> Suppose I want to supply a singleton class object that will sit
> between my intranet asp.net app and MS SQL database, doing al the
> chemistry with connections etc inside of it.
> The problem is that I don't really know how to keep the object
> persistent for all the requests nade within the app.
> I need the object to live for certain periods of time, and I need it
> to be easily accessible from aspx.cs files' code.
> I guess I will be creating it in global.asax on application start;
> where do I store it then? How do I address it?
For an exellent article about the singleton pattern (in C#) see:
http://www.yoda.arachsys.com/csharp/singleton.html

0 comments:

Post a Comment