473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Singletons in asp

Hey guys

Just a quick question. If i had a static var, then all users coming onto my
site will be sharing the same var. So if i have a class that is a singleton
would the same happen there?

Basically i have a class that will only ever have one instance so, singleton
makes sense. But due to asp and lots of connecting users it had me wondering
if the singleton would work as one isntance per user or one instance for all
users (not what i want)

Thanks
Mar 19 '07 #1
7 1223
First, I'll assume you're speaking of asp.net and not just asp.

They are different things.

Here is an example of a asp.net singleton:

10/24/2005
Web Session Wrapper for storing and retrieving objects
http://sholliday.spaces.live.com/blog/
PS
You should mark
public class WebSessionDataStore

as [Serializable]

and make any objects you put in there serializable if you go to sql server
session state management.

"PokerMan" <no****@pokercat.co.ukwrote in message
news:uk**************@TK2MSFTNGP04.phx.gbl...
Hey guys

Just a quick question. If i had a static var, then all users coming onto
my
site will be sharing the same var. So if i have a class that is a
singleton
would the same happen there?

Basically i have a class that will only ever have one instance so,
singleton
makes sense. But due to asp and lots of connecting users it had me
wondering
if the singleton would work as one isntance per user or one instance for
all
users (not what i want)

Thanks


Mar 19 '07 #2
yes .net sorry.

I am more wanting to know how it will handle a singleton implementation not
how to implement one, tho i cant see an singleton implementation on that
blog? Is it very different to a standard one on .net?

"sloan" <sl***@ipass.netwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
First, I'll assume you're speaking of asp.net and not just asp.

They are different things.

Here is an example of a asp.net singleton:

10/24/2005
Web Session Wrapper for storing and retrieving objects
http://sholliday.spaces.live.com/blog/
PS
You should mark
public class WebSessionDataStore

as [Serializable]

and make any objects you put in there serializable if you go to sql server
session state management.

"PokerMan" <no****@pokercat.co.ukwrote in message
news:uk**************@TK2MSFTNGP04.phx.gbl...
>Hey guys

Just a quick question. If i had a static var, then all users coming onto
my
>site will be sharing the same var. So if i have a class that is a
singleton
>would the same happen there?

Basically i have a class that will only ever have one instance so,
singleton
>makes sense. But due to asp and lots of connecting users it had me
wondering
>if the singleton would work as one isntance per user or one instance for
all
>users (not what i want)

Thanks



Mar 19 '07 #3
If you have static values it is one instance for *all* users. If you want
one instance for *each* user then you could store your object in the
Session.

"PokerMan" <no****@pokercat.co.ukwrote in message
news:uk**************@TK2MSFTNGP04.phx.gbl...
Hey guys

Just a quick question. If i had a static var, then all users coming onto
my site will be sharing the same var. So if i have a class that is a
singleton would the same happen there?

Basically i have a class that will only ever have one instance so,
singleton makes sense. But due to asp and lots of connecting users it had
me wondering if the singleton would work as one isntance per user or one
instance for all users (not what i want)

Thanks

Mar 19 '07 #4
Ah found ur singletom implementation on the blog, my apologies. And its
similar to mine, not sure why you use a method and dont set the instance as
a property get{} but its the same in essence.

So in answer to my original question a singleton will work as i expect?
Single instance per user, not one instance effected by all users?

"sloan" <sl***@ipass.netwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
First, I'll assume you're speaking of asp.net and not just asp.

They are different things.

Here is an example of a asp.net singleton:

10/24/2005
Web Session Wrapper for storing and retrieving objects
http://sholliday.spaces.live.com/blog/
PS
You should mark
public class WebSessionDataStore

as [Serializable]

and make any objects you put in there serializable if you go to sql server
session state management.

"PokerMan" <no****@pokercat.co.ukwrote in message
news:uk**************@TK2MSFTNGP04.phx.gbl...
>Hey guys

Just a quick question. If i had a static var, then all users coming onto
my
>site will be sharing the same var. So if i have a class that is a
singleton
>would the same happen there?

Basically i have a class that will only ever have one instance so,
singleton
>makes sense. But due to asp and lots of connecting users it had me
wondering
>if the singleton would work as one isntance per user or one instance for
all
>users (not what i want)

Thanks



Mar 19 '07 #5

Did you look at entry at the correct date?

private WebSessionDataStore() //constructor
{
this.m_itemCollection = new HybridDictionary();
}
/// <summary>
/// Singleton representing WebSessionDataStore.
/// </summary>
/// <returns></returns>
public static WebSessionDataStore GetInstance()
{
//other stuff here
}
Singleton is a DESIGN PATTERN, not "just an asp.net thing".

http://www.dofactory.com/Patterns/PatternSingleton.aspx
static/shared variables are another thing.
Based on your description of what you want
if the singleton would work as one isntance per user or one instance for
allusers (not what i want)

I've shown you how to create a true SINGLETON for the web environment.

You can find more by googling also:
http://www.google.com/search?hl=en&q...+%22asp.net%22

"PokerMan" <no****@pokercat.co.ukwrote in message
news:e2**************@TK2MSFTNGP02.phx.gbl...
yes .net sorry.

I am more wanting to know how it will handle a singleton implementation
not
how to implement one, tho i cant see an singleton implementation on that
blog? Is it very different to a standard one on .net?

"sloan" <sl***@ipass.netwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
First, I'll assume you're speaking of asp.net and not just asp.

They are different things.

Here is an example of a asp.net singleton:

10/24/2005
Web Session Wrapper for storing and retrieving objects
http://sholliday.spaces.live.com/blog/
PS
You should mark
public class WebSessionDataStore

as [Serializable]

and make any objects you put in there serializable if you go to sql
server
session state management.

"PokerMan" <no****@pokercat.co.ukwrote in message
news:uk**************@TK2MSFTNGP04.phx.gbl...
Hey guys

Just a quick question. If i had a static var, then all users coming
onto
my
site will be sharing the same var. So if i have a class that is a
singleton
would the same happen there?

Basically i have a class that will only ever have one instance so,
singleton
makes sense. But due to asp and lots of connecting users it had me
wondering
if the singleton would work as one isntance per user or one instance
for
all
users (not what i want)

Thanks



Mar 19 '07 #6

My singleton example piggybacks off of SESSION, therefore you will get "one
per user".

I use a method ... because I think thats what GOF (gang of four) does.

http://www.dofactory.com/Patterns/PatternSingleton.aspx
uses a method also.

.....

Again, because I piggy back off of Session, its "one per user".

If I were to piggyback off of Application (object, instead of Session)
(which I actually do in another scenario)....
it would be "all users".


"PokerMan" <no****@pokercat.co.ukwrote in message
news:eS**************@TK2MSFTNGP04.phx.gbl...
Ah found ur singletom implementation on the blog, my apologies. And its
similar to mine, not sure why you use a method and dont set the instance
as
a property get{} but its the same in essence.

So in answer to my original question a singleton will work as i expect?
Single instance per user, not one instance effected by all users?

"sloan" <sl***@ipass.netwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
First, I'll assume you're speaking of asp.net and not just asp.

They are different things.

Here is an example of a asp.net singleton:

10/24/2005
Web Session Wrapper for storing and retrieving objects
http://sholliday.spaces.live.com/blog/
PS
You should mark
public class WebSessionDataStore

as [Serializable]

and make any objects you put in there serializable if you go to sql
server
session state management.

"PokerMan" <no****@pokercat.co.ukwrote in message
news:uk**************@TK2MSFTNGP04.phx.gbl...
Hey guys

Just a quick question. If i had a static var, then all users coming
onto
my
site will be sharing the same var. So if i have a class that is a
singleton
would the same happen there?

Basically i have a class that will only ever have one instance so,
singleton
makes sense. But due to asp and lots of connecting users it had me
wondering
if the singleton would work as one isntance per user or one instance
for
all
users (not what i want)

Thanks



Mar 19 '07 #7
it can be coded either way, depends on how you code it.

-- bruce (sqlwork.com)

PokerMan wrote:
Ah found ur singletom implementation on the blog, my apologies. And its
similar to mine, not sure why you use a method and dont set the instance as
a property get{} but its the same in essence.

So in answer to my original question a singleton will work as i expect?
Single instance per user, not one instance effected by all users?

"sloan" <sl***@ipass.netwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>First, I'll assume you're speaking of asp.net and not just asp.

They are different things.

Here is an example of a asp.net singleton:

10/24/2005
Web Session Wrapper for storing and retrieving objects
http://sholliday.spaces.live.com/blog/
PS
You should mark
public class WebSessionDataStore

as [Serializable]

and make any objects you put in there serializable if you go to sql server
session state management.

"PokerMan" <no****@pokercat.co.ukwrote in message
news:uk**************@TK2MSFTNGP04.phx.gbl...
>>Hey guys

Just a quick question. If i had a static var, then all users coming onto
my
>>site will be sharing the same var. So if i have a class that is a
singleton
>>would the same happen there?

Basically i have a class that will only ever have one instance so,
singleton
>>makes sense. But due to asp and lots of connecting users it had me
wondering
>>if the singleton would work as one isntance per user or one instance for
all
>>users (not what i want)

Thanks


Mar 19 '07 #8

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

Similar topics

5
by: stephan beal | last post by:
Good morning, C++ users, i've been hesitating to post this, primarily because i know that most of you here are *way* ahead of me in C++ and i'm a little embarassed about the possibility of some...
11
by: Tito | last post by:
I have two questions about the singletons' chapter of Alexei Alexandrescu's "C++ Modern Design". 1. In the beginning of the chapter Alexei states that a "singleton" class implementation made of...
3
by: Dominik Rau | last post by:
Hi. I've got the following problem here: In my application, I use a lot of Singletons, that are implemented as described in Gamma et al. (shortened): //.h class Singleton{ public: static...
8
by: 6tc1 | last post by:
Hi all, I'm having a problem where in my solution that contains multiple projects - I instantiate a singleton class in one assembly and then if another assembly tries to use that singleton class...
11
by: John Fly | last post by:
I'm working on a large project(from scratch). The program is essentially a data file processor, the overall view is this: A data file is read in, validated and stored in a memory structure...
6
by: Steven Watanabe | last post by:
PEP 8 says, "Comparisons to singletons like None should always be done with 'is' or 'is not', never the equality operators." I know that "is" is an identity operator, "==" and "!=" are the equality...
5
by: Omega | last post by:
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...
6
by: =?Utf-8?B?R29yZG8=?= | last post by:
Hello everyone, I've been trying for some time now to move to C++/CLI, but I have several large legacy C++ static libraries I need to use. When I set up a simple solution with a C++/CLI Winforms...
7
by: adam.timberlake | last post by:
I was reading an article on TalkPHP (http://www.talkphp.com/ showthread.php?t=1304) about singletons but I'm afraid I don't understand why I need to use them. I understand how to code them...
12
by: Craig Allen | last post by:
Hey, forgive me for just diving in, but I have a question I was thinking of asking on another list but it really is a general question so let me ask it here. It's about how to approach making...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.