sure, it's stored for all users in the static field " private static
Singleton uniqueInstance; "
-- Instead you can save it in the HttpContext.Items collection, so it is a
"singleton per HttpRequest" instead:
public class Singleton
{
private Singleton()
{
}
static Singleton(){
_ticket = new object();
}
private static object _ticket;
public static Singleton getInstance(HttpContext context)
{
Singleton uniqueInstance = context.Items[_ticket] as Singleton;
if(uniqueInstance == null)
{
uniqueInstance = new Singleton();
context.Items.Add(_ticket, uniqueInstance);
}
return uniqueInstance;
}
}
R-)
"Rich" <> wrote in message
news: oups.com...
> The following code produced a singleton object with application scope
> when it should have had page scope:
>
> public class Singleton
> {
> private static Singleton uniqueInstance = null;
> private Singleton()
> {
> }
> public static Singleton getInstance()
> {
> if (uniqueInstance == null)
> uniqueInstance = new Singleton();
> return uniqueInstance;
> }
> }
> public partial class Default1
age
> {
> Singleton s = Singleton.getInstance();
> void Page_Load(...)
> {...}
> void Button1Clicked(...)
> {...}
> }
> public partial class Default2
age
> {
> Singleton s = Singleton.getInstance(); // this retrieved the
> instance from Default1
> void Page_Load(...)
> {...}
> void Button1Clicked(...)
> {...}
> }
>
>
>
> Can anyone please explain how a Singleton object created within a Page
> class is able to get application scope?
>
>
> Rich
>