title: Dependency injection with unity in a class library project
body: <p>I am new with the dependency injection pattern. I'm a little confused about few things.</p>
  
  <h2>Scenario:</h2>
  
  <p>I have a class library project called 'MailCore'. This project has interfaces and classes that perform all email sending stuff.
  I have an MVC project called 'The site'. It uses the 'MailCore' project to send email. I have Unity in this project and the UnityContainer is registered and things are working fine.</p>
  
  <p>I also have another class library library project called 'SiteRepo'. Sometimes, to perform some specific tasks, I have to send email from this project. Therefore the 'MailCore' project is referenced in this project, too.</p>
  
  <h2>Problem:</h2>
  
  <p>I have installed Unity from NuGet in the 'SiteRepo' project and it doesn't seem to create any UnityConfig in this class library project.
  How would I register a UnityContainer here?</p>
  
  <h2>Code:</h2>
  
  <p>TheSite:</p>
  
  <pre><code>Public class JobController : Controller
  {
      private readonly IEmailBuilder mailBuilder;
      public JobController(IEmailBuilder mailBuilder)
      {
          this.mailBuilder = mailBuilder;
  
      }
      public ActionResult Create(....)
      {
        JobRepo j = new JobRepo();
        j.Create(....);
      }
  
  }
  </code></pre>
  
  <p>UnityConfig (this is in the web app 'The Site'):</p>
  
  <pre><code>public static class UnityConfig
  {
      public static void RegisterComponents()
      {
          var container = new UnityContainer();
  
          // register all your components with the container here
          // it is NOT necessary to register your controllers
  
          // e.g. container.RegisterType&lt;ITestService, TestService&gt;();
  
          container.RegisterType&lt;IEmailBuilder, EmailBuilder&gt;();
  
          DependencyResolver.SetResolver(new UnityDependencyResolver(container));
      }
  }
  </code></pre>
  
  <p>SiteRepo:</p>
  
  <pre><code>Public class JobRepo()
  {
     Public bool Create(...) 
     {
         //some other code to create a job....
  
         //have to send email using MailCore !! The problem area in concern..
     }
  }
  </code></pre>