title: Checking additional static properties on lazy singleton pattern (Jon Skeet singleton)
body: <p>I'm implementing <a href="http://csharpindepth.com/Articles/General/Singleton.aspx" rel="nofollow noreferrer">Jon Skeet's Singleton</a> using <code>System.Lazy&lt;T&gt;</code>.  </p>
  
  <p>My singleton differs slightly though.  My singleton class represents the configuration of one of my services, and that service has a connection to a database.  I have an additional readonly static property that returns <code>true</code> if my service is disconnected.</p>
  
  <p>I did this by checking the <code>IsValueCreated</code> property on the lazy object first, and calling <code>Value</code> if it has not been created to ensure that when I check my <code>ConnectionString</code> property, my singleton has been instantiated.  </p>
  
  <p>Is there a more elegant way of implementing <code>Disconnected</code>?  Is disconnected thread safe in this current implementation (without <code>lock</code>s)? Any insight would be greatly appreciated. </p>
  
  <p>Example code below: 
  </p>
  
  <pre><code>    public sealed class MyServiceConfiguration {
          private static Lazy&lt;MyServiceConfiguration&gt; lazy = new Lazy&lt;MyServiceConfiguration&gt;(() =&gt; new MyServiceConfiguration());
  
          private static string ConnectionString = "";
  
          public static MyServiceConfiguration Instance { get { return lazy.Value; } }
  
          public static bool Disconnected {
              get {
                  if (!lazy.IsValueCreated) { lazy.Value; }
                  return ConnectionString == "";
              }
          }
  
          private MyServiceConfiguration() {
              //...additional service configuration options...
              ConnectionString = "someConnectionString";
          }
      }
  </code></pre>