title: Create a dotnet tool for EF Core data seed
body: <p>As mentioned in this <a href="https://blogs.msdn.microsoft.com/dotnet/2016/09/29/implementing-seeding-custom-conventions-and-interceptors-in-ef-core-1-0/" rel="nofollow noreferrer">post</a> I am seeding database data on the Startup of an ASP.NET Core project as follows:</p>
  
  <pre><code>public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) {
  
    using (var serviceScope = app.ApplicationServices.GetRequiredService&lt;IServiceScopeFactory&gt;().CreateScope()) {  
      var context = serviceScope.ServiceProvider.GetService&lt;MyContext&gt;();       
      context.Database.Migrate();
      context.EnsureSeedData();
  
    }
  
  }
  </code></pre>
  
  <p>But the same post also recommends to seed data manually, </p>
  
  <blockquote>
    <p>Please note that, in general, it is recommended to apply these operations manually (rather than performing migrations and seeding automatically on startup), to avoid racing conditions when there are multiple servers, and unintentional changes.</p>
  </blockquote>
  
  <p>which I would prefer and using a dotnet tool as follows:</p>
  
  <pre><code>dotnet seed -c &lt;Context&gt; -s &lt;SeedData&gt;
  </code></pre>
  
  <p>where:<br>
  - Context is the DbContext to be used. Default is used if none is specified.<br>
  - SeedData is a class containing the Data Insertion logic.  </p>
  
  <p>Is it possible to create such a custom dotnet tool?</p>
  
  <p>Can the DbContext be used inside the tool?</p>