title: Is there a way to run Entity Framework migrations before Hosted Services start
body: <p>When I created my .NET Core 5 application, I ran EF migrations by executing the migration code at the top of my Startup.Configure (...) method:</p>
  <pre><code>public class Startup 
  {
      . . .
      public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
      {
          using (var scope = app.ApplicationServices.CreateScope())
          {
               ApplicationDbContext context = scope.ServiceProvider.GetService&lt;ApplicationDbContext&gt;();
               context.Database.Migrate();
          }
          . . .
      }
  }
  </code></pre>
  <p>This all worked well enough until I recently added some Hosted Services that rely on the DB and changes applied by the migrations. Now, if I have migrations that need to be applied before the hosted services start, my app crashes at startup because the hosted services are starting before the migrations run.</p>
  <p>Is there a way to fix this? Is there a way to have the migrations run before the hosted services are started?</p>