title: Lazy Singleton with property that references parent in constructor
body: <p>I have a Singleton which functions as a context object for a web application. This Singleton follows Jon Skeets excellent <a href="http://csharpindepth.com/articles/general/singleton.aspx" rel="nofollow">Lazy Singleton model</a>.</p>
  
  <p>The end result, is a <code>Context.Current</code> object which serves as a reference point for many functions.</p>
  
  <p>The problem I'm running into is with a Property of this object which is a class called <code>Providers</code>. It gives me OAuth information like ClientId about a series of cloud providers.</p>
  
  <p>ClientIds change based on your endpoint for most providers, so in the Constructor for each Provider, I check ... you guessed it, <code>Context.Current.DeploymentType</code> which is an <code>ENUM</code> that tells me which environment I'm in.</p>
  
  <p>Calling an object during it's instantiate is quite bad form, and I end up with a:</p>
  
  <p><code>ValueFactory attempted to access the Value property of this instance.</code></p>
  
  <p>Now, I could simply not reference <code>Context.Current.DeploymentType</code> in the constructor for <code>Provider</code>, and just do the same work that the <code>ENUM</code> does when it instantiates over and over again, but it feels inefficient.</p>
  
  <p>I could create the <code>ENUM</code> separately, and then again for the <code>Context.Current</code>, but that feels wrong as well.</p>
  
  <p>My current code is:</p>
  
  <pre><code>public Providers AllProviders = Providers.Instance;
  </code></pre>
  
  <p>Is there a way to say:</p>
  
  <pre><code>public Providers AllProviders {get; don't instantiate me until someone calls me}
  </code></pre>