title: Entity Framework Core use windows service
body: <p>Currently in the process of building a multi tired application using EF Core for my data access layer and I feel like I'm running in to a problem and I'm not 100% certain I can use it at the moment.</p>
  
  <p>Essentially I'm designing my application into the following components</p>
  
  <ul>
  <li>windows assembly</li>
  <li>asp.net mvc core web app</li>
  <li>windows service x2</li>
  <li>unit test  </li>
  </ul>
  
  <p>in good design I'm putting as much of my domain in my assembly so that I can reuse it as much as possible, but this is where I'm running into issues. I'm currently unable to use EF in my unit test app.</p>
  
  <p>I am currently overriding OnConfiguring to set the database connection string but when I attempt to use the context in a unit testI continually get the following exception message: "Instance failure"</p>
  
  <p>My context is dirt simple right now and only has one entity and looks as follows:</p>
  
  <pre><code>public partial class CdiContext : DbContext
  {
      private string ConnectionString { get; set; }
      private bool IsService { get; set; }
      public CdiContext(string connectionString, bool isService)
      {
          ConnectionString = connectionString;
          IsService = isService;
      }
  
      protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
      {
          optionsBuilder.UseSqlServer(ConnectionString);
      }
  
      public DbSet&lt;Region&gt; Regions { get; set; }
   }
  </code></pre>
  
  <p>In an effort to rule out the unit test as the problem I've also created a simple console application and even it throws the same exception so I'm really lost as to how to proceed.     </p>
  
  <pre><code> CdiContext context =  new CdiContext(@"Data Source=localhost\\SQLEXPRESS;Initial Catalog=herp-interface;Persist Security Info=True;User ID=sa;Password=herpaderp;Pooling=true", true);
   var regions = context.Regions.ToList();
  
   Console.ReadLine();
  </code></pre>
  
  <p><strong>The question is what am I doing that's wrong where I am unable to use a EF context from a windows assembly in any type of project aside from an ASP.NET Core MVC app?</strong></p>