diff --git a/src/Infrastructure/Data/CatalogContextSeed.cs b/src/Infrastructure/Data/CatalogContextSeed.cs index c2fb2f5..f369094 100644 --- a/src/Infrastructure/Data/CatalogContextSeed.cs +++ b/src/Infrastructure/Data/CatalogContextSeed.cs @@ -10,9 +10,9 @@ namespace Microsoft.eShopWeb.Infrastructure.Data public class CatalogContextSeed { public static async Task SeedAsync(CatalogContext catalogContext, - ILoggerFactory loggerFactory, int? retry = 0) + ILoggerFactory loggerFactory, int retry = 0) { - int retryForAvailability = retry.Value; + var retryForAvailability = retry; try { if (catalogContext.Database.IsSqlServer()) @@ -46,56 +46,55 @@ namespace Microsoft.eShopWeb.Infrastructure.Data } catch (Exception ex) { - if (retryForAvailability < 10) - { - retryForAvailability++; - var log = loggerFactory.CreateLogger(); - log.LogError(ex.Message); - await SeedAsync(catalogContext, loggerFactory, retryForAvailability); - } + if (retryForAvailability >= 10) throw; + + retryForAvailability++; + var log = loggerFactory.CreateLogger(); + log.LogError(ex.Message); + await SeedAsync(catalogContext, loggerFactory, retryForAvailability); throw; } } static IEnumerable GetPreconfiguredCatalogBrands() { - return new List() + return new List { - new CatalogBrand("Azure"), - new CatalogBrand(".NET"), - new CatalogBrand("Visual Studio"), - new CatalogBrand("SQL Server"), - new CatalogBrand("Other") + new("Azure"), + new(".NET"), + new("Visual Studio"), + new("SQL Server"), + new("Other") }; } static IEnumerable GetPreconfiguredCatalogTypes() { - return new List() + return new List { - new CatalogType("Mug"), - new CatalogType("T-Shirt"), - new CatalogType("Sheet"), - new CatalogType("USB Memory Stick") + new("Mug"), + new("T-Shirt"), + new("Sheet"), + new("USB Memory Stick") }; } static IEnumerable GetPreconfiguredItems() { - return new List() + return new List { - new CatalogItem(2,2, ".NET Bot Black Sweatshirt", ".NET Bot Black Sweatshirt", 19.5M, "http://catalogbaseurltobereplaced/images/products/1.png"), - new CatalogItem(1,2, ".NET Black & White Mug", ".NET Black & White Mug", 8.50M, "http://catalogbaseurltobereplaced/images/products/2.png"), - new CatalogItem(2,5, "Prism White T-Shirt", "Prism White T-Shirt", 12, "http://catalogbaseurltobereplaced/images/products/3.png"), - new CatalogItem(2,2, ".NET Foundation Sweatshirt", ".NET Foundation Sweatshirt", 12, "http://catalogbaseurltobereplaced/images/products/4.png"), - new CatalogItem(3,5, "Roslyn Red Sheet", "Roslyn Red Sheet", 8.5M, "http://catalogbaseurltobereplaced/images/products/5.png"), - new CatalogItem(2,2, ".NET Blue Sweatshirt", ".NET Blue Sweatshirt", 12, "http://catalogbaseurltobereplaced/images/products/6.png"), - new CatalogItem(2,5, "Roslyn Red T-Shirt", "Roslyn Red T-Shirt", 12, "http://catalogbaseurltobereplaced/images/products/7.png"), - new CatalogItem(2,5, "Kudu Purple Sweatshirt", "Kudu Purple Sweatshirt", 8.5M, "http://catalogbaseurltobereplaced/images/products/8.png"), - new CatalogItem(1,5, "Cup White Mug", "Cup White Mug", 12, "http://catalogbaseurltobereplaced/images/products/9.png"), - new CatalogItem(3,2, ".NET Foundation Sheet", ".NET Foundation Sheet", 12, "http://catalogbaseurltobereplaced/images/products/10.png"), - new CatalogItem(3,2, "Cup Sheet", "Cup Sheet", 8.5M, "http://catalogbaseurltobereplaced/images/products/11.png"), - new CatalogItem(2,5, "Prism White TShirt", "Prism White TShirt", 12, "http://catalogbaseurltobereplaced/images/products/12.png") + new(2,2, ".NET Bot Black Sweatshirt", ".NET Bot Black Sweatshirt", 19.5M, "http://catalogbaseurltobereplaced/images/products/1.png"), + new(1,2, ".NET Black & White Mug", ".NET Black & White Mug", 8.50M, "http://catalogbaseurltobereplaced/images/products/2.png"), + new(2,5, "Prism White T-Shirt", "Prism White T-Shirt", 12, "http://catalogbaseurltobereplaced/images/products/3.png"), + new(2,2, ".NET Foundation Sweatshirt", ".NET Foundation Sweatshirt", 12, "http://catalogbaseurltobereplaced/images/products/4.png"), + new(3,5, "Roslyn Red Sheet", "Roslyn Red Sheet", 8.5M, "http://catalogbaseurltobereplaced/images/products/5.png"), + new(2,2, ".NET Blue Sweatshirt", ".NET Blue Sweatshirt", 12, "http://catalogbaseurltobereplaced/images/products/6.png"), + new(2,5, "Roslyn Red T-Shirt", "Roslyn Red T-Shirt", 12, "http://catalogbaseurltobereplaced/images/products/7.png"), + new(2,5, "Kudu Purple Sweatshirt", "Kudu Purple Sweatshirt", 8.5M, "http://catalogbaseurltobereplaced/images/products/8.png"), + new(1,5, "Cup White Mug", "Cup White Mug", 12, "http://catalogbaseurltobereplaced/images/products/9.png"), + new(3,2, ".NET Foundation Sheet", ".NET Foundation Sheet", 12, "http://catalogbaseurltobereplaced/images/products/10.png"), + new(3,2, "Cup Sheet", "Cup Sheet", 8.5M, "http://catalogbaseurltobereplaced/images/products/11.png"), + new(2,5, "Prism White TShirt", "Prism White TShirt", 12, "http://catalogbaseurltobereplaced/images/products/12.png") }; } } diff --git a/src/Infrastructure/Data/EfRepository.cs b/src/Infrastructure/Data/EfRepository.cs index bd1fdee..f454c12 100644 --- a/src/Infrastructure/Data/EfRepository.cs +++ b/src/Infrastructure/Data/EfRepository.cs @@ -49,7 +49,7 @@ namespace Microsoft.eShopWeb.Infrastructure.Data public async Task AddAsync(T entity, CancellationToken cancellationToken = default) { - await _dbContext.Set().AddAsync(entity); + await _dbContext.Set().AddAsync(entity, cancellationToken); await _dbContext.SaveChangesAsync(cancellationToken); return entity; diff --git a/src/Infrastructure/Infrastructure.csproj b/src/Infrastructure/Infrastructure.csproj index 0655fb5..b5f04b2 100644 --- a/src/Infrastructure/Infrastructure.csproj +++ b/src/Infrastructure/Infrastructure.csproj @@ -6,8 +6,6 @@ - -