If you consider Application object in asp.net you will find it implemented as singleton as Application object is shared throuughout the application and
No, Application is property of type HttpApplicationState.
HttpApplicationState is just a sealesed public class, it's not created a singleton class.
However logically Application property will be assigned with only one object throught the application.
mutliple application objects to HttpApplicationState will be created for muliple applications.
So it is just logically mainted as singleton rather created HttpApplicationState as singleton class.
I agree that implementation alwasy can be altered to our needs., however, I could not see any realtime class defined as singleton physically as mentioned in GangOfFour example.
All the static objects from BCL are implemented as Singleton pattern. If you need an example to justify my statement, please see the below code
lblTime.ForeColor = SystemColors.ControlText;
I'm sure that you must be aware that the SystemColors is a class.
On a second thought, check for the information about DataRowComparer. This static class DataRowComparer is a member of System.Data.The summary for this static class is mentioned by Microsoft as, "Returns a singleton instance of the System.Data.DataRowComparer<TRow> class."
Your explanation is ambiguous. ServiceHost is not singleton. SingletonInstance points to service object which is passed when
ServiceHost(Object, uri[]) syntax is used. If Other syntax is used which accepts type (and InstanceContextMode is not single, this object is null.
Contributor
2350 Points
1014 Posts
any Singleton in .NET Framework?
Mar 15, 2011 06:56 AM|duttavr|LINK
Could anyone please reply me if .NET Framework has any inbuilt Singleton class used?
Contributor
7304 Points
1672 Posts
Re: any Singleton in .NET Framework?
Mar 15, 2011 07:38 AM|tehremo|LINK
Nothing "built in", but here is a pretty straight forward article on implementing:
http://msdn.microsoft.com/en-us/library/ff650316.aspx
Contributor
2350 Points
1014 Posts
Re: any Singleton in .NET Framework?
Mar 15, 2011 07:55 AM|duttavr|LINK
Thanks tehremo for the reply.
Sorry If my question was not clear. I know how to implment.
I'm just trying to find if any real time example where .NET Framework already used it.
Contributor
4108 Points
1099 Posts
Re: any Singleton in .NET Framework?
Mar 15, 2011 08:09 AM|naveenj|LINK
Hi duttavr,
The site dofactory.com has some examples for doing in C# and .NET Optimized environment.
Check out this link: Singleton Design Pattern
Naveen Jose
ASP.NET Freelancer, Consultant
Please remember to click Mark as Answer on the post that helps you
Contributor
2350 Points
1014 Posts
Re: any Singleton in .NET Framework?
Mar 15, 2011 10:27 AM|duttavr|LINK
Let me reiterate my query.
I would just like to know if Microsoft implemented Singleton class in any of Microsoft's frameworks.
Prefarablly in below as I work with them.
Member
60 Points
9 Posts
Re: any Singleton in .NET Framework?
Apr 05, 2011 06:43 AM|vibhumittal|LINK
Hi duttavr,
If you consider Application object in asp.net you will find it implemented as singleton as Application object is shared throuughout the application and
no other instance of same can exists.
Contributor
2350 Points
1014 Posts
Re: any Singleton in .NET Framework?
Apr 05, 2011 01:15 PM|duttavr|LINK
No, Application is property of type HttpApplicationState.
HttpApplicationState is just a sealesed public class, it's not created a singleton class.
However logically Application property will be assigned with only one object throught the application.
mutliple application objects to HttpApplicationState will be created for muliple applications.
So it is just logically mainted as singleton rather created HttpApplicationState as singleton class.
I agree that implementation alwasy can be altered to our needs., however, I could not see any realtime class defined as singleton physically as mentioned in GangOfFour example.
Member
30 Points
26 Posts
Re: any Singleton in .NET Framework?
Jun 01, 2012 03:37 AM|dskcheck|LINK
Hi Rajaraman,
All the static objects from BCL are implemented as Singleton pattern. If you need an example to justify my statement, please see the below code
I'm sure that you must be aware that the SystemColors is a class.
On a second thought, check for the information about DataRowComparer. This static class DataRowComparer is a member of System.Data. The summary for this static class is mentioned by Microsoft as, "Returns a singleton instance of the System.Data.DataRowComparer<TRow> class."
Hope this helps.
Contributor
5054 Points
1330 Posts
Re: any Singleton in .NET Framework?
Aug 16, 2012 01:46 PM|kushalrdalal|LINK
I think so when you host the wcf service internally microsoft uses singleton to make sure it has only one instance available.
Check this links-
http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehost.singletoninstance.aspx
My Blog
LinkedIn Profile
None
0 Points
1 Post
Re: any Singleton in .NET Framework?
Dec 27, 2012 03:38 PM|tilakrajchandan|LINK
Your explanation is ambiguous. ServiceHost is not singleton. SingletonInstance points to service object which is passed when ServiceHost(Object, uri[]) syntax is used. If Other syntax is used which accepts type (and InstanceContextMode is not single, this object is null.