473,667 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?
Nov 18 '05 #1
4 1712
Store it in the Application Context...

Reference it through the application context.
"Sergei Shelukhin" <ra******@home. domonet.ru> wrote in message
news:2t******** *****@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?

Nov 18 '05 #2
"Sergei Shelukhin" <ra******@home. domonet.ru> wrote in
news:2t******** *****@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 (RE********@rog ers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 18 '05 #3
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:ug******** ******@TK2MSFTN GP10.phx.gbl...
Store it in the Application Context...

Reference it through the application context.
"Sergei Shelukhin" <ra******@home. domonet.ru> wrote in message
news:2t******** *****@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?


Nov 18 '05 #4
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


Nov 18 '05 #5

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

Similar topics

9
1550
by: VidalSasoon | last post by:
I am trying to set up a singleton since it seems like the best solution to my problem. I have a an object that I want to initialize when the program starts then I just want to call it like a static function.... so i want to create instances of that object. I need to send parameters to initialize my object properly in the singleton. that is where i am starting to have problems. I starting to wonder if this is bad style. is this the...
21
2457
by: Sharon | last post by:
I wish to build a framework for our developers that will include a singleton pattern. But it can not be a base class because it has a private constructor and therefore can be inherit. I thought maybe a Template can be use for that, but C# does not support Templates (will be C# generics in mid 2005). Does anyone have a solution on how the singleton pattern can be written, in C#, as a framework/ infrastructure class, so users can use this...
4
1410
by: Srini | last post by:
Hi , Can anyone tell me when I can use singleton pattern. Will it be good for implementing the dataaccess Layer. Will it be usefull for the buisness object layer . Could you give me a practicle example for using the singleton object. Regards, Srini
5
3979
by: Bob | last post by:
Does anyone know of any adverse affects of using singleton data access objects in an ASP.NET Web Service? I've been forced to implement it this way but it just doesn't seem right to me. I haven't been able to find a single example of someone doing it this way and that's usually not a good sign. I'm afraid that there may be subtle problems that won't show up quickly because the production environment will not be hitting the web service at...
1
1235
by: Diffident | last post by:
Guys, I have been cracking my head over this concept in .NET framework. I have read many posts on this topic but not clear about this and hence I am posting it again. If you have designed your class based on singleton pattern where ONLY ONE instance of class exists for the WHOLE APPLICATION DOMAIN....how can the public methods in that class be thread-safe? I have read thru posts where they say that singleton class methods are...
14
3019
by: Paul Bromley | last post by:
Forgive my ignorance on this one as I am trying to use a Singleton class. I need to use this to have one instance of my Class running and I think I understand how to do this. My question however is can a singleton class have a number of paramterised constructors enabling me to pass in parameters or not? I am trying to use the following to send in a parmeter to a constructor, but getting an error with it. I have a feeling that I am not...
2
2414
by: baba | last post by:
Hi all, I'm quite new to C#. I am trying to implement some basics reusable classes using this language and the .NET Framework technology. What I'm trying to do now is to implement a singleton class. I did have a look at the Microsoft "Patterns and Practices" article "Implementing Singleton in C#" (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpatterns/html/ImpSingletonInCsharp.asp)
11
1858
by: donet programmer | last post by:
Can somebody comment on the usage of the singleton pattern for maintaining session variables?? Thanks
6
2079
by: Palvinder Singh | last post by:
Hello google group peeps, I am new to remoting, but have a grasp of it. I am trying to create a server/client application, which will be deployed over an intranet. I have upwards of five clients that connect to a main server. The client application sets the state of several switchs (on/off by means of clicking a button). When a switch is turned on/off, its state is updated on the server, which will then raise an event to update...
0
8788
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8646
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7390
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6203
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.