2

In Asp.Net in what scenario i will use singleton as most of the job can be done with Session / Cache / Static by checking whether it is null nor not.

please refer to my previous question

Singleton Pattern / Check for Null - While using Asp.Net with Session

Community
  • 1
  • 1
user841683
  • 335
  • 6
  • 17

1 Answers1

12

I think you are confusing the particular implementation of the Singleton pattern with the concept itself. Your previous question / implementation could be interpreted as Singleton within a user session, if you saved in the Application cache instead it would be a Singleton for the ASP.NET application.

Singleton just means that there is only one instance of a particular object at any time and this is enforced by the application - how you enforce this is an implementation detail that might vary depending on your choice of platform / language.

In particular for ASP.NET you may still use the standard singleton pattern for C# using a static variable (see Implementing the Singleton Pattern in C#). There will only be multiple instances if your application is used in a web farm scenario, also refer to this SO thread: Are static class instances unique to a request or a server in ASP.NET?

Community
  • 1
  • 1
BrokenGlass
  • 158,293
  • 28
  • 286
  • 335