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.
Please Mark as Answer, if it answers you, also correct me if I'm wrong.
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.
duttavr
Contributor
4035 Points
1079 Posts
any Singleton in .NET Framework?
Mar 15, 2011 10:56 AM|LINK
Could anyone please reply me if .NET Framework has any inbuilt Singleton class used?
Please Mark as Answer, if it answers you, also correct me if I'm wrong.
tehremo
Star
10540 Points
1704 Posts
Re: any Singleton in .NET Framework?
Mar 15, 2011 11:38 AM|LINK
Nothing "built in", but here is a pretty straight forward article on implementing:
http://msdn.microsoft.com/en-us/library/ff650316.aspx
duttavr
Contributor
4035 Points
1079 Posts
Re: any Singleton in .NET Framework?
Mar 15, 2011 11:55 AM|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.
Please Mark as Answer, if it answers you, also correct me if I'm wrong.
naveenj
Contributor
6164 Points
1130 Posts
Re: any Singleton in .NET Framework?
Mar 15, 2011 12:09 PM|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
duttavr
Contributor
4035 Points
1079 Posts
Re: any Singleton in .NET Framework?
Mar 15, 2011 02:27 PM|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.
Please Mark as Answer, if it answers you, also correct me if I'm wrong.
vibhumittal
Member
78 Points
9 Posts
Re: any Singleton in .NET Framework?
Apr 05, 2011 10:43 AM|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.
duttavr
Contributor
4035 Points
1079 Posts
Re: any Singleton in .NET Framework?
Apr 05, 2011 05:15 PM|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.
Please Mark as Answer, if it answers you, also correct me if I'm wrong.
dskcheck
Member
105 Points
31 Posts
Re: any Singleton in .NET Framework?
Jun 01, 2012 07:37 AM|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.
kushalrdalal
Contributor
7200 Points
1288 Posts
Re: any Singleton in .NET Framework?
Aug 16, 2012 05:46 PM|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
tilakrajchan...
Member
2 Points
1 Post
Re: any Singleton in .NET Framework?
Dec 27, 2012 07:38 PM|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.