title: Have some values available before accessing a singleton the first time or how to initialize object in singleton
body: <p>This is my current singleton:</p>
  
  <pre><code>public sealed class DataCollection
  {
      // creating singleton instance (http://csharpindepth.com/Articles/General/Singleton.aspx)
      private static readonly Lazy&lt;DataCollection&gt; lazy = new Lazy&lt;DataCollection&gt;(() =&gt; new DataCollection());
  
      public User currentUser { get; set; }
  
      public Filter currentFilter { get; set; }
  
      // fully laziness
      public static DataCollection Instance {
          get{
              return lazy.Value;
          }
      }
  
      private DataCollection ()
      {
      }
  }
  </code></pre>
  
  <p>In my <code>Filter</code> object I have the following:</p>
  
  <pre><code>public class Filter
  {
      public bool newEntries { get; set; }
      public List&lt;PerfLoc&gt; costCentres { get; set; }
  
      public Filter ()
      {
          newEntries = false;
          costCentres = new List&lt;PerfLoc&gt; ();
          read ();
      }
  
      public void read(){
          // do some initialization here (e.g. read some stored values in)
      }
  }
  </code></pre>
  
  <p>Now I want to access the <code>Filter</code> like this:</p>
  
  <pre><code>globalData = DataCollection.Instance;
  bool new = globalData.currentFilter.newEntries;
  </code></pre>
  
  <p>But here the <code>Filter</code> object isn't initialized and therefore null. I could create a new filter object and set it and then access it but it would be best if the initialization is done in the <code>Singleton</code> instance.</p>
  
  <p>So I thought about an initialization like this:</p>
  
  <pre><code>private DataCollection ()
  {
      currentFilter = new Filter();
  }
  </code></pre>
  
  <p>Is this the correct way without compromising the singleton pattern? There should be a value available before accessing the <code>Filter</code> for the first time. Later I thought to create a new <code>Filter</code> object and set it with my <code>globalData</code> instance.</p>