locked
any Singleton in .NET Framework? RRS feed

  • Question

  • User619554136 posted

    Could anyone please reply me if .NET Framework has any inbuilt Singleton class used?

    Tuesday, March 15, 2011 6:56 AM

All replies

  • User-451260051 posted

    Nothing "built in", but here is a pretty straight forward article on implementing:

    http://msdn.microsoft.com/en-us/library/ff650316.aspx

    Tuesday, March 15, 2011 7:38 AM
  • User619554136 posted

    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.

    Tuesday, March 15, 2011 7:55 AM
  • User-1227788583 posted

    Hi duttavr,

    The site dofactory.com has some examples for doing in C# and .NET Optimized environment.

    Check out this link: Singleton Design Pattern 

    Tuesday, March 15, 2011 8:09 AM
  • User619554136 posted

    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.

    • Microsoft .NET Framework Classes.
    • WCF Frame work Classes
    • ASP.NET MVC Framework Classes
    • ADO.NET
    • Enterprise Library classes
    Tuesday, March 15, 2011 10:27 AM
  • User318339461 posted

    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.

     

    Tuesday, April 5, 2011 6:43 AM
  • User619554136 posted

    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.

    Tuesday, April 5, 2011 1:15 PM
  • User-854291756 posted

    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

    			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."

    Hope this helps.

    Friday, June 1, 2012 3:37 AM
  • User-1662538993 posted

    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

    Thursday, August 16, 2012 1:46 PM
  • User1312941417 posted

    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.

    Thursday, December 27, 2012 3:38 PM