diff --git a/ClubService.API/Program.cs b/ClubService.API/Program.cs index 6935919..ad96c6e 100644 --- a/ClubService.API/Program.cs +++ b/ClubService.API/Program.cs @@ -1,5 +1,6 @@ using ClubService.API; using ClubService.API.ApplicationConfigurations; +using ClubService.Domain.Repository; using ClubService.Infrastructure.DbContexts; using Microsoft.AspNetCore.Authentication; using Microsoft.EntityFrameworkCore; @@ -66,7 +67,16 @@ app.UseSwaggerUI(options => { options.SwaggerEndpoint("/swagger/v1/swagger.json", "ClubServiceV1"); }); await eventStoreDbContext.Database.EnsureCreatedAsync(); - await eventStoreDbContext.SeedTestData(); + + try + { + await eventStoreDbContext.SeedTestData(); + } + catch (DbUpdateException) + { + var logger = services.GetRequiredService>(); + logger.LogDuplicateSeedData(); + } await readStoreDbContext.Database.EnsureDeletedAsync(); await readStoreDbContext.Database.EnsureCreatedAsync(); diff --git a/ClubService.Domain/Repository/ILoggerService.cs b/ClubService.Domain/Repository/ILoggerService.cs index bc9cac1..2a0b254 100644 --- a/ClubService.Domain/Repository/ILoggerService.cs +++ b/ClubService.Domain/Repository/ILoggerService.cs @@ -65,4 +65,5 @@ public interface ILoggerService void LogEmailMessageRelayStop(); void LogSystemOperatorRegistered(Guid id); void LogInvalidEMailAddress(string emailAddress); + void LogDuplicateSeedData(); } \ No newline at end of file diff --git a/ClubService.Infrastructure/Logging/LoggerService.cs b/ClubService.Infrastructure/Logging/LoggerService.cs index 852fa31..2c36a5d 100644 --- a/ClubService.Infrastructure/Logging/LoggerService.cs +++ b/ClubService.Infrastructure/Logging/LoggerService.cs @@ -325,4 +325,9 @@ public void LogInvalidEMailAddress(string emailAddress) { logger.LogError("The following email address is invalid: {emailMessageRecipientEMailAddress}", emailAddress); } + + public void LogDuplicateSeedData() + { + logger.LogInformation("Seed data already seeded"); + } } \ No newline at end of file