Last post Jan 04, 2016 08:58 AM by gerrylowry
Jan 02, 2016 06:04 AM|pr_nimbalkar|LINK
Can anybody tells me the real time usage of Singleton pattern in Asp.NET web application?
Jan 02, 2016 06:35 AM|gerrylowry|LINK
you MUST learn to use Google; many, including myself, have answered this question!
see here: http://forums.asp.net/post/4769770.aspx
sample Google search: http://lmgtfy.com/?q=singleton+site%3Aforums.asp.net
click the above link to ask Google to search for singleton site:forums.asp.net
Jan 02, 2016 06:58 AM|pr_nimbalkar|LINK
Thanks for Reply !! But had you gone though my question carefully, I am asking the
real time usage / example not what is singleton and etc. ? That i know. already.
For your info.. I joined this blog as when i don't get satisfied answer on google.
Jan 02, 2016 07:14 AM|gerrylowry|LINK
if you want the best answer, you need to refine your question* imho.
real time usage
any program that is currently executing is running in real time
what kind of example?
* "Clarity is important, both in question and in answer"
via Google search: msdn c# singleton example
https://msdn.microsoft.com/en-us/library/ee817670.aspx "Exploring the Singleton Design Pattern"
http://csharpindepth.com/Articles/General/Singleton.aspx by Jon Skeet
https://msdn.microsoft.com/en-us/library/ff650849.aspx "Singlton" also
Example: https://msdn.microsoft.com/en-us/library/ff650316.aspx "implementing Singlton in c#"
Jan 02, 2016 01:38 PM|pr_nimbalkar|LINK
Jan 04, 2016 05:30 AM|TechView|LINK
Jan 04, 2016 08:58 AM|gerrylowry|LINK
can you please clarify your post? ...
DBContext is not a Singleton.
Also, https://msdn.microsoft.com/en-us/library/ff650316.aspx "implementing Singleton in C#" in the static example creates the Singleton as a
Basically singleton pattern is used to create a class where an instance of that class should used all over the project.
Judith Bishop gives us this definition:
"The purpose of the Singleton pattern is to ensure that there is only
one instance of a class, and that there is a global access point to that object."
TechView, your example is not a Singleton; you are creating a context that derives from DbContext.
see https://msdn.microsoft.com/en-ca/data/jj729737.aspx "Working with DbContext", especially the section "Lifetime".
one tends to create multiple instances of the same context class; for example, see http://www.entityframeworktutorial.net/EntityFramework4.3/update-entity-using-dbcontext.aspx where
multiple instances of the context SchoolDBEntitites are created in a disconnected scenario.
TechView, the reason your example is not a Singleton is because it is possible to create
multiple instances of a context derived from DbContext.