title: Connection String DI in ASP.NET Core
body: <p>I am not sure what I am doing wrong here, I want to use the connection string from appsettings.json and use DI to setup my DbContext for use.</p>
  
  <pre><code>{
    "ConnectionStrings": {
      "DarkwinterDatabase": "server=localhost;userid=user;pwd=pass;port=3306;database=Darkwinter;sslmode=none;"
    },
    ...
  }
  </code></pre>
  
  <p>In the ConfigureServices method in Startup.cs I have the following code.</p>
  
  <pre><code>services.AddDbContext&lt;PostContext&gt;(options =&gt;
      options.UseMySQL(Configuration.GetConnectionString("DarkwinterDatabase")));
  </code></pre>
  
  <p>My DbContext has one DbSet and accepts DbContextOptions to pass to base to be initialized. This is where I think I am wrong but should DI pass options to this class?</p>
  
  <pre><code>public class PostContext : DbContext
  {
      public PostContext(DbContextOptions options) : base(options) { }
      public DbSet&lt;Post&gt; Post { get; set; }
  }
  </code></pre>
  
  <p>How ever when I try to use my Context I get an error: There is no argument given that corresponds to the required formal parameter 'options' of 'PostContext.PostContext(DbContextOptions)</p>
  
  <pre><code>using(var db = new PostContext())
  {
      var posts = db.Post.ToList();
      return View(posts);
  }
  </code></pre>
  
  <p>This makes sense since I didn't pass one in but I thought that the service should do that? I know I am thinking about this the wrong way and was hoping someone would take the time to explain it to me.</p>