title: How do I replace the obsolete Microsoft.Practices.Unity.Configuration.ContainerElement.Configure method in my Unity solution?
body: <p>I have a Unity application that is running and working perfectly but we are currently in the process of cleaning up our code by acting on all the compilation warnings.</p>
  
  <p>I get a warning on the following piece of code because of the obsolete Microsoft.Practices.Unity.Configuration.ContainerElement.Configure method:</p>
  
  <pre><code>var map = new ExeConfigurationFileMap { ExeConfigFilename = GetConfigFolderForFile("unity.config") };
  Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
  var section = (UnityConfigurationSection)config.GetSection(SectionName);
  
  if (section != null)
  {
  
      var container = new UnityContainer();
  
      foreach (ContainerElement containerElement in section.Containers)
      {
          containerElement.Configure(container);
      }
  
      Container = container; // Set the main container
  }
  </code></pre>
  
  <p>I'd like to replace it with the UnityConfigurationSection.Configure method as suggested but can't see that they are equivalent because of being at different levels of the object hierarchy.</p>
  
  <p>I've tried:</p>
  
  <pre><code>var map = new ExeConfigurationFileMap { ExeConfigFilename = GetConfigFolderForFile("unity.config") };
  Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
  var section = (UnityConfigurationSection)config.GetSection(SectionName);
  
  if (section != null)
  {
      IUnityContainer container = new UnityContainer();
  
      container = section.Configure(container);
  
      Container = container; // Set the main container
  }
  </code></pre>
  
  <p>but that falls down with null references.</p>
  
  <p>How should I be updating the code to eliminate use of the obsolete method?</p>