Skip to content

Commit e1acb4e

Browse files
committed
Clean up database utility
1 parent d199452 commit e1acb4e

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

src/MaintenanceLog/DatabaseUtility.cs

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
1-
using System.Threading;
2-
using MaintenanceLog.Data;
1+
using MaintenanceLog.Data;
32
using Microsoft.EntityFrameworkCore;
4-
using Microsoft.EntityFrameworkCore.Migrations;
53

64
namespace MaintenanceLog;
75

86
public static class DatabaseUtility
97
{
10-
public static async Task EnsureDbCreatedAndSeedWithDefaults(DbContextOptions<ApplicationDbContext> options, IMigrator migrator)
8+
public static async Task EnsureDbCreatedAndSeedWithDefaults(DbContextOptions<ApplicationDbContext> options)
119
{
1210
var factory = new LoggerFactory();
1311
var builder = new DbContextOptionsBuilder<ApplicationDbContext>(options)
1412
.UseLoggerFactory(factory);
1513

1614
using var context = new ApplicationDbContext(builder.Options);
1715

18-
//if (!await context.Database.EnsureCreatedAsync())
19-
//{
20-
// Console.WriteLine("Database already exists or was not otherwise created.");
21-
//}
22-
2316
try
2417
{
2518
// not good with distributed UI... but for now...

src/MaintenanceLog/Program.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,8 @@
9292

9393
// This section sets up and seeds the database. Seeding is NOT normally
9494
// handled this way in production.
95-
await using var scope = app.Services.GetRequiredService<IServiceScopeFactory>().CreateAsyncScope();
96-
var options = scope.ServiceProvider.GetRequiredService<DbContextOptions<ApplicationDbContext>>();
97-
var migrator = scope.ServiceProvider.GetService<IMigrator>();
98-
await MaintenanceLog.DatabaseUtility.EnsureDbCreatedAndSeedWithDefaults(options, migrator);
95+
var options = app.Services.GetRequiredService<DbContextOptions<ApplicationDbContext>>();
96+
await MaintenanceLog.DatabaseUtility.EnsureDbCreatedAndSeedWithDefaults(options);
9997

10098
app.MapControllers();
10199

0 commit comments

Comments
 (0)