public async static Task SeedAsync(GigContext gigContext, ILoggerFactory loggerFactory, int?retry = 0) { var log = loggerFactory.CreateLogger <GigContextSeed>(); int retryForAvailability = retry.Value; try { log.LogInformation("Applying migrations..."); // TODO: Only run this if using a real database gigContext.Database.Migrate(); if (!gigContext.Gigs.Any()) { log.LogInformation("Adding data - seeding..."); gigContext.Gigs.AddRange( GetPreconfiguredGigs()); await gigContext.SaveChangesAsync(); } } catch (Exception ex) { if (retryForAvailability < 10) { retryForAvailability++; log.LogError(ex.Message); await SeedAsync(gigContext, loggerFactory, retryForAvailability); } throw; } }
public EfRepository(GigContext dbContext) { _dbContext = dbContext; }