title: How use Dependency Injection with Unity from Migration Code First?
body: <p>I need to use dependency injection in the Migrations\Configuration.cs for seeding values from my service layer. I use Unity to do that. My Unity container work fine in the entire web site because I instantiate all Interfaces via Constructor class. But I cannot do that in the Configuration.cs file because Code First use an empty Constructor.</p>
  
  <p>Here is my code. Tell me what I’m doing wrong?</p>
  
  <pre><code>internal sealed class Configuration : DbMigrationsConfiguration&lt;ApplicationDbContext&gt;
      {
          private IGenderService _genderService;
  
          public Configuration()
          {
              AutomaticMigrationsEnabled = false;
  
              using (var container = UnityConfig.GetConfiguredContainer())
              {
                  var isRegister = container.IsRegistered&lt;IGenderService&gt;(); // Return true!
                  _genderService = container.Resolve&lt;IGenderService&gt;();
  
                  if (_genderService == null)
                      throw new Exception("Doh! Empty");
                  else
                      throw new Exception("Yeah! Can continue!!");
              };
          }
  
          public Configuration(IGenderService genderService) // Cannot use this constructor because of Code First!!!
          {
              _genderService = genderService;
          }
  }
  </code></pre>
  
  <p>The _genderService is always null and I got this error in the same way : </p>
  
  <blockquote>
    <p>Type 'Microsoft.Practices.Unity.ResolutionFailedException' in assembly
    'Microsoft.Practices.Unity, Version=3.5.0.0, Culture=neutral,
    PublicKeyToken=31bf3856ad364e35' is not marked as serializable.</p>
  </blockquote>
  
  <p>Thank,</p>
  
  <p>David</p>