Merge pull request #294 from dotnet-architecture/fixing-container-startup
Fixing container startup
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Ardalis.GuardClauses" Version="1.2.9" />
|
<PackageReference Include="Ardalis.GuardClauses" Version="1.2.9" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="2.2.6" />
|
||||||
<PackageReference Include="System.Security.Claims" Version="4.3.0" />
|
<PackageReference Include="System.Security.Claims" Version="4.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate
|
namespace Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Ardalis.GuardClauses;
|
using Ardalis.GuardClauses;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate
|
namespace Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
using Ardalis.EFCore.Extensions;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||||
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
|
using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate;
|
||||||
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate;
|
using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate;
|
||||||
|
|
||||||
namespace Microsoft.eShopWeb.Infrastructure.Data
|
namespace Microsoft.eShopWeb.Infrastructure.Data
|
||||||
{
|
{
|
||||||
|
|
||||||
public class CatalogContext : DbContext
|
public class CatalogContext : DbContext
|
||||||
{
|
{
|
||||||
public CatalogContext(DbContextOptions<CatalogContext> options) : base(options)
|
public CatalogContext(DbContextOptions<CatalogContext> options) : base(options)
|
||||||
@@ -22,11 +23,142 @@ namespace Microsoft.eShopWeb.Infrastructure.Data
|
|||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder builder)
|
protected override void OnModelCreating(ModelBuilder builder)
|
||||||
{
|
{
|
||||||
base.OnModelCreating(builder);
|
//Intentionally rolling back this change to fix issue: https://github.com/dotnet-architecture/eShopOnWeb/issues/292
|
||||||
builder.ApplyAllConfigurationsFromCurrentAssembly();
|
//Will follow up after issue has been resolved.
|
||||||
|
//base.OnModelCreating(builder);
|
||||||
|
//builder.ApplyAllConfigurationsFromCurrentAssembly();
|
||||||
|
|
||||||
// alternately this is built-in to EF Core 2.2
|
// alternately this is built-in to EF Core 2.2
|
||||||
//builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
|
//builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
|
||||||
|
|
||||||
|
builder.Entity<Basket>(ConfigureBasket);
|
||||||
|
builder.Entity<CatalogBrand>(ConfigureCatalogBrand);
|
||||||
|
builder.Entity<CatalogType>(ConfigureCatalogType);
|
||||||
|
builder.Entity<CatalogItem>(ConfigureCatalogItem);
|
||||||
|
builder.Entity<Order>(ConfigureOrder);
|
||||||
|
builder.Entity<OrderItem>(ConfigureOrderItem);
|
||||||
|
builder.Entity<Address>(ConfigureAddress);
|
||||||
|
builder.Entity<CatalogItemOrdered>(ConfigureCatalogItemOrdered);
|
||||||
|
builder.Entity<BasketItem>(ConfigureBasketItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConfigureBasketItem(EntityTypeBuilder<BasketItem> builder)
|
||||||
|
{
|
||||||
|
builder.Property(bi => bi.UnitPrice)
|
||||||
|
.IsRequired(true)
|
||||||
|
.HasColumnType("decimal(18,2)");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConfigureCatalogItemOrdered(EntityTypeBuilder<CatalogItemOrdered> builder)
|
||||||
|
{
|
||||||
|
builder.Property(cio => cio.ProductName)
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.IsRequired();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConfigureAddress(EntityTypeBuilder<Address> builder)
|
||||||
|
{
|
||||||
|
builder.Property(a => a.ZipCode)
|
||||||
|
.HasMaxLength(18)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(a => a.Street)
|
||||||
|
.HasMaxLength(180)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(a => a.State)
|
||||||
|
.HasMaxLength(60);
|
||||||
|
|
||||||
|
builder.Property(a => a.Country)
|
||||||
|
.HasMaxLength(90)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(a => a.City)
|
||||||
|
.HasMaxLength(100)
|
||||||
|
.IsRequired();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConfigureBasket(EntityTypeBuilder<Basket> builder)
|
||||||
|
{
|
||||||
|
var navigation = builder.Metadata.FindNavigation(nameof(Basket.Items));
|
||||||
|
|
||||||
|
navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConfigureCatalogItem(EntityTypeBuilder<CatalogItem> builder)
|
||||||
|
{
|
||||||
|
builder.ToTable("Catalog");
|
||||||
|
|
||||||
|
builder.Property(ci => ci.Id)
|
||||||
|
.ForSqlServerUseSequenceHiLo("catalog_hilo")
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(ci => ci.Name)
|
||||||
|
.IsRequired(true)
|
||||||
|
.HasMaxLength(50);
|
||||||
|
|
||||||
|
builder.Property(ci => ci.Price)
|
||||||
|
.IsRequired(true)
|
||||||
|
.HasColumnType("decimal(18,2)");
|
||||||
|
|
||||||
|
builder.Property(ci => ci.PictureUri)
|
||||||
|
.IsRequired(false);
|
||||||
|
|
||||||
|
builder.HasOne(ci => ci.CatalogBrand)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey(ci => ci.CatalogBrandId);
|
||||||
|
|
||||||
|
builder.HasOne(ci => ci.CatalogType)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey(ci => ci.CatalogTypeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConfigureCatalogBrand(EntityTypeBuilder<CatalogBrand> builder)
|
||||||
|
{
|
||||||
|
builder.ToTable("CatalogBrand");
|
||||||
|
|
||||||
|
builder.HasKey(ci => ci.Id);
|
||||||
|
|
||||||
|
builder.Property(ci => ci.Id)
|
||||||
|
.ForSqlServerUseSequenceHiLo("catalog_brand_hilo")
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(cb => cb.Brand)
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConfigureCatalogType(EntityTypeBuilder<CatalogType> builder)
|
||||||
|
{
|
||||||
|
builder.ToTable("CatalogType");
|
||||||
|
|
||||||
|
builder.HasKey(ci => ci.Id);
|
||||||
|
|
||||||
|
builder.Property(ci => ci.Id)
|
||||||
|
.ForSqlServerUseSequenceHiLo("catalog_type_hilo")
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
builder.Property(cb => cb.Type)
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConfigureOrder(EntityTypeBuilder<Order> builder)
|
||||||
|
{
|
||||||
|
var navigation = builder.Metadata.FindNavigation(nameof(Order.OrderItems));
|
||||||
|
|
||||||
|
navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
|
||||||
|
|
||||||
|
builder.OwnsOne(o => o.ShipToAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConfigureOrderItem(EntityTypeBuilder<OrderItem> builder)
|
||||||
|
{
|
||||||
|
builder.OwnsOne(i => i.ItemOrdered);
|
||||||
|
|
||||||
|
builder.Property(oi => oi.UnitPrice)
|
||||||
|
.IsRequired(true)
|
||||||
|
.HasColumnType("decimal(18,2)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user