Can a Singleton be used with ASP.Net?

R

Rick

A coworker has brought up the following quote from a book as
confirmation that we cannot use Singletons in ASP.Net application
code, at least at the ASP.Net tier.

I am looking for references to other documentation that confirms this
quote or refutes it or expert comment on whether to use a Singleton in
the ASP.Net web projects.

The following quote is from the book Programming Distributed
Applications with COM+ and Microsoft Visual Basic 6.0, Second Edition,
by Ted Pattison, Microsoft Press, 2000.

"An object that is shared across multiple clients is often called a
"singleton". Developers typically design with singletons in order to
share data across multiple clients. While the use of singleton objects
might be acceptable in some single-user scenarios, you should
definitely avoid it in COM+ applications. Every client should get its
own private objects. If multiple clients require access to the same
data, you should store this data in shared memory or in a database.
You can then devise a design in which each client creates a private
object that accesses this shared data." -- Chapter 7 "Sharing
Resources in a COM+ application".

I disagree with him as I have used Singletons before in ASP.Net code
and I thought they were working as intended. I haven't seen any
authoritative statement on MSDN or elsewhere, written specifically in
the context of ASP.Net and the .Net Framework that would indicate that
Singletons are incompatible with ASP.Net and cannot provide the
typical benefits of Singletons when used in ASP.Net Web Projects.

Thanks much,
Rick
 
S

Scott Allen

The quote does not say that you CANNOT use singletons in ASP.NET, what
it is doing is trying to DISCOURAGE the use of singletons in ASP.NET
and other server based applications. Singletons can be difficult to
implement and maintain, and can be the source of bottlenecks in server
side code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top