Since I used to be a Java programmer, I used to write singletons in c# like this:

public class MySingleton {
 
      private static MySingleton instance;
      
      public static MySingleton Instance
      {
         get
         {
            if (instance == null)
            {
               lock(typeof(MySingleton))
               {
                  if (instance == null)
                  {
                     instance = new MySingleton();
                  }   	            
               }
            }
            return instance;
         }
 
      private MySingleton()
      {
            // do init
      }
}

Until I wanted to show a colleague the data & object factory site, a design patterns website specifically targeted at c# development.

Continue Reading »