dotnet / aspire-samples

MIT License
560 stars 153 forks source link

QUESTION: in the DatabaseMigrations sample, why is this code so complex? #347

Open burtonrodman opened 1 week ago

burtonrodman commented 1 week ago

I appreciate that sample of having a separate worker to apply database migrations.

My question is, why does this code seem to duplicate the logic of the in-built context.Database.Migrate()? What does this gain us vs simpler code? Is the canonical example not transactional? Does breaking out the code provide better logging?

vs.

https://github.com/dotnet/aspire-samples/blob/main/samples/DatabaseMigrations/DatabaseMigrations.MigrationService/ApiDbInitializer.cs

Canonical example:

using (var scope = app.Services.CreateScope())
{
  var services = scope.ServiceProvider;

  var context = services.GetRequiredService<IngestionDbContext>();
  context.Database.Migrate();
}