title: Should I make an IUnityContainer object use a Singleton pattern?
body: <p>I am new to using Unity and IoC/DI concepts.  I started with the concept by rolling my own via James Kovacs' show on <a href="http://www.dnrtv.com/default.aspx?showNum=126" rel="nofollow noreferrer">dnrTV </a> in a test.  </p>
  
  <p>His example had the Container run as a singleton accessed through a static method in an IoC class so you could register types at a startup and resolve the type throughout your application.  </p>
  
  <p>I know this was not full featured and was to mainly show the concepts of IoC.  </p>
  
  <p>I am now attempting to use Unity in a project.  </p>
  
  <p>In my Main() I create a new container, but once my WinForms opens, the container falls out of scope and is disposed.  Later on in the program, when I try to resolve a type I no longer have the original container and its registered types.  </p>
  
  <p>Is there a concept or implementation construct I am missing?</p>
  
  <p>My current thought is to create something like this:  </p>
  
  <pre><code>public static class Container
  {
      private static readonly object syncRoot = new object();
      private static volatile IUnityContainer instance;
  
      public static IUnityContainer Instance
      {
          get
          {
              if (instance == null)
              {
                  lock (syncRoot)
                  {
                      if (instance == null)
                      {
                          instance = new UnityContainer();
                      }
                  }
              }
              return instance;
          }
      }
  }
  </code></pre>
  
  <p>I'm pretty sure this will work, it just doesn't seem right.  </p>