title: Acceptable to use a Type for a Dictionary Key?
body: <p>I would like to make a class that can store at most one copy of an object. All the objects stored here will share the same base class, and I would like to be able to get an object based on it's type.</p>
  
  <p>I've come up with this solution so far, but I feel like I'm doing something wrong with using a Type for the Dictionary key.</p>
  
  <p>Base class used in multiple modules</p>
  
  <pre><code>interface ISessionVariables { }
  </code></pre>
  
  <p>Example of common singleton class used for accessing </p>
  
  <pre><code>public class SessionVariables
  {
      private object _sync = new object();
      private Dictionary&lt;Type, ISessionVariables&gt; _sessionVariables = 
          new Dictionary&lt;Type, ISessionVariables&gt;;
  
      public T Get&lt;T&gt;()
          where T : ISessionVariable, new()
      {
          lock (_sync)
          {
              ISessionVariables rtnValue = null;
              if (_sessionVariables.TryGetValue(typeof(T), out rtnValue))
                  return (T)rtnValue;
  
              rtnValue = new T();
              _sessionVariables.Add(typeof(T), rtnValue);
  
              return (T)rtnValue;
          }
      }
  }
  </code></pre>
  
  <p>This way I can call it like this from individual modules</p>
  
  <pre><code>SessionVariableSingleton.Get&lt;ModuleASessionVars&gt;().PropertyA;
  
  SessionVariableSingleton.Get&lt;ModuleCSessionVars&gt;().PropertyC;
  </code></pre>
  
  <p>Is this an acceptable way of storing this kind of data structure? Or is there a better alternative using a List or a dictionary without a Type key?</p>