title: How to abstract a singleton class?
body: <p>This is how I write my singleton classes.</p>
  
  <pre><code>public class MyClass
  {
      /// &lt;summary&gt;
      /// Singleton
      /// &lt;/summary&gt;
      private static MyClass instance;
  
      /// &lt;summary&gt;
      /// Singleton access.
      /// &lt;/summary&gt;
      public static MyClass Instance
      {
          get
          {
              if (_instance == null)
              {
                  _instance = new MyClass();
              }
              return _instance;
          }
      }
  
      private MyClass() { .... }
  }
  </code></pre>
  
  <h2>How To Create A Singleton Pattern That Is Reusable?</h2>
  
  <p>Singleton patterns present the following challenges.</p>
  
  <ul>
  <li>The constructor is <code>private</code> or <code>protected</code>.</li>
  <li>A base class can't instantiate an inherited class. So you can reuse a common abstract <code>MyAbstractSingletonClass</code>.</li>
  <li>It has to have a local read-only property to get the instance.</li>
  </ul>
  
  <h2>The Problem</h2>
  
  <p>I'm using this pattern on a number of classes and always have to write the same code. How can I write something that is reused whenever I need a singleton?</p>