title: Should I use Unity Config file or Code to register types and instances?
body: <p>Finally started to configure an IoC Container!</p>
  
  <p>I'm using Unity and have configured it to have my objects registered using the config file:</p>
  
  <p>e.g.</p>
  
  <pre><code>      &lt;container&gt;
          &lt;register type="ILogger" mapTo="Logger"&gt;
            &lt;lifetime type="singleton"/&gt;
          &lt;/register&gt;
          &lt;register type="IPdfWriter" mapTo="PdfWriter"&gt;
            &lt;lifetime type="perthread" /&gt;
            &lt;constructor /&gt;      
          &lt;/register&gt;
  &lt;/container&gt;
  </code></pre>
  
  <p>I've reached a point where I doubt this is a good approach to register types.</p>
  
  <p>For example a class of mine is dependent on the ICacheManager from Microsoft Enterprise Library Caching block and the below should be injected to it:</p>
  
  <pre><code>EnterpriseLibraryContainer.Current.GetInstance&lt;ICacheManager&gt;()
  </code></pre>
  
  <p>and that doesn't seem to be possible using just unity config settings.</p>
  
  <p>It seems to me that always it's better to register the types using code rather than the config file.</p>
  
  <p>What's your experience/advise in this?</p>
  
  <p>Thanks</p>