Exemplo n.º 1
0
        public void SingletonTest()
        {
            // The client code.
            var s1 = SingletonPattern.GetInstance();
            var s2 = SingletonPattern.GetInstance();

            s1.Should().Be(s2);
            s1.DoSomeBusinessLogic();
        }
Exemplo n.º 2
0
 public static SingletonPattern GetSingleInstance()
 {
     // Double checking lock
     if (SingletonInstance == null)
     {
         // applying lock so that only one thread can access the
         // critical section of code at a time
         lock (padLock)
         {
             if (SingletonInstance == null)
             {
                 SingletonInstance = new SingletonPattern();
             }
         }
     }
     return(SingletonInstance);
 }
Exemplo n.º 3
0
 public static void Singleton()
 {
     //Two Example of 3) Singleton
     SingletonPattern.ConfigurationExample();
     SingletonPattern.BusinessRuleExample();
 }