title: Is it better to create a singleton to access unity container or pass it through the application?
body: <p>I am dipping my toe into using a IoC framework and I have choosen to use Unity. One of the things that I still don't fully understand is how to resolve objects deeper into the application. I suspect I just haven't had the light bulb on moment that will make it clear.</p>
  
  <p>So I am trying do something like the following in psuedo'ish code</p>
  
  <pre><code>void Workflow(IUnityContatiner contatiner, XPathNavigator someXml)
  {
     testSuiteParser = container.Resolve&lt;ITestSuiteParser&gt;
     TestSuite testSuite = testSuiteParser.Parse(SomeXml) 
     // Do some mind blowing stuff here
  }
  </code></pre>
  
  <p>So the testSuiteParser.Parse does the following</p>
  
  <pre><code>TestSuite Parse(XPathNavigator someXml)
  {
      TestStuite testSuite = ??? // I want to get this from my Unity Container
      List&lt;XPathNavigator&gt; aListOfNodes = DoSomeThingToGetNodes(someXml)
  
      foreach (XPathNavigator blah in aListOfNodes)
      {
          //EDIT I want to get this from my Unity Container
          TestCase testCase = new TestCase() 
          testSuite.TestCase.Add(testCase);
      } 
  }
  </code></pre>
  
  <p>I can see three options:</p>
  
  <ol>
  <li>Create a Singleton to store my unity container that I can access anywhere. I really am not a fan of this approach. Adding a dependency like that to use a dependency injection framework seems a little on the odd side.</li>
  <li>Pass the IUnityContainer to my TestSuiteParser class and every child of it (assume it is n levels deep or in reality about 3 levels deep). Passing IUnityContainer around everywhere just looks odd. I may just need to get over this.</li>
  <li>Have the light bulb moment on the right way to use Unity. Hoping someone can help flick the switch.</li>
  </ol>
  
  <p>[EDIT]
  One of things that I wasn't clear on is that I want to create a new instance of test case for each iteration of the foreach statement. The example above needs to parse a test suite configuration and populate a collection of test case objects</p>