refactored the Infrastructure project (#553)
This commit is contained in:
committed by
GitHub
parent
729354297f
commit
fee2bbce3d
@@ -10,9 +10,9 @@ namespace Microsoft.eShopWeb.Infrastructure.Data
|
|||||||
public class CatalogContextSeed
|
public class CatalogContextSeed
|
||||||
{
|
{
|
||||||
public static async Task SeedAsync(CatalogContext catalogContext,
|
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
|
try
|
||||||
{
|
{
|
||||||
if (catalogContext.Database.IsSqlServer())
|
if (catalogContext.Database.IsSqlServer())
|
||||||
@@ -46,56 +46,55 @@ namespace Microsoft.eShopWeb.Infrastructure.Data
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (retryForAvailability < 10)
|
if (retryForAvailability >= 10) throw;
|
||||||
{
|
|
||||||
retryForAvailability++;
|
retryForAvailability++;
|
||||||
var log = loggerFactory.CreateLogger<CatalogContextSeed>();
|
var log = loggerFactory.CreateLogger<CatalogContextSeed>();
|
||||||
log.LogError(ex.Message);
|
log.LogError(ex.Message);
|
||||||
await SeedAsync(catalogContext, loggerFactory, retryForAvailability);
|
await SeedAsync(catalogContext, loggerFactory, retryForAvailability);
|
||||||
}
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static IEnumerable<CatalogBrand> GetPreconfiguredCatalogBrands()
|
static IEnumerable<CatalogBrand> GetPreconfiguredCatalogBrands()
|
||||||
{
|
{
|
||||||
return new List<CatalogBrand>()
|
return new List<CatalogBrand>
|
||||||
{
|
{
|
||||||
new CatalogBrand("Azure"),
|
new("Azure"),
|
||||||
new CatalogBrand(".NET"),
|
new(".NET"),
|
||||||
new CatalogBrand("Visual Studio"),
|
new("Visual Studio"),
|
||||||
new CatalogBrand("SQL Server"),
|
new("SQL Server"),
|
||||||
new CatalogBrand("Other")
|
new("Other")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static IEnumerable<CatalogType> GetPreconfiguredCatalogTypes()
|
static IEnumerable<CatalogType> GetPreconfiguredCatalogTypes()
|
||||||
{
|
{
|
||||||
return new List<CatalogType>()
|
return new List<CatalogType>
|
||||||
{
|
{
|
||||||
new CatalogType("Mug"),
|
new("Mug"),
|
||||||
new CatalogType("T-Shirt"),
|
new("T-Shirt"),
|
||||||
new CatalogType("Sheet"),
|
new("Sheet"),
|
||||||
new CatalogType("USB Memory Stick")
|
new("USB Memory Stick")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static IEnumerable<CatalogItem> GetPreconfiguredItems()
|
static IEnumerable<CatalogItem> GetPreconfiguredItems()
|
||||||
{
|
{
|
||||||
return new List<CatalogItem>()
|
return new List<CatalogItem>
|
||||||
{
|
{
|
||||||
new CatalogItem(2,2, ".NET Bot Black Sweatshirt", ".NET Bot Black Sweatshirt", 19.5M, "http://catalogbaseurltobereplaced/images/products/1.png"),
|
new(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(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(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(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(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(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(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(2,5, "Kudu Purple Sweatshirt", "Kudu Purple Sweatshirt", 8.5M, "http://catalogbaseurltobereplaced/images/products/8.png"),
|
||||||
new CatalogItem(1,5, "Cup<T> White Mug", "Cup<T> White Mug", 12, "http://catalogbaseurltobereplaced/images/products/9.png"),
|
new(1,5, "Cup<T> White Mug", "Cup<T> 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(3,2, ".NET Foundation Sheet", ".NET Foundation Sheet", 12, "http://catalogbaseurltobereplaced/images/products/10.png"),
|
||||||
new CatalogItem(3,2, "Cup<T> Sheet", "Cup<T> Sheet", 8.5M, "http://catalogbaseurltobereplaced/images/products/11.png"),
|
new(3,2, "Cup<T> Sheet", "Cup<T> 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,5, "Prism White TShirt", "Prism White TShirt", 12, "http://catalogbaseurltobereplaced/images/products/12.png")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace Microsoft.eShopWeb.Infrastructure.Data
|
|||||||
|
|
||||||
public async Task<T> AddAsync(T entity, CancellationToken cancellationToken = default)
|
public async Task<T> AddAsync(T entity, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
await _dbContext.Set<T>().AddAsync(entity);
|
await _dbContext.Set<T>().AddAsync(entity, cancellationToken);
|
||||||
await _dbContext.SaveChangesAsync(cancellationToken);
|
await _dbContext.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
|
|||||||
@@ -6,8 +6,6 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Ardalis.EFCore.Extensions" Version="1.1.0" />
|
|
||||||
<PackageReference Include="Ardalis.Specification" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" Version="4.1.0" />
|
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" Version="4.1.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.10" />
|
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.10" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.11" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.11" />
|
||||||
|
|||||||
Reference in New Issue
Block a user