The repetitive fields in the configuration classes in the Ordering.Infrastructure project were gathered here by creating a base class.

This commit is contained in:
veysel mutlu 2021-09-10 22:48:47 +03:00
parent 4814e1bce2
commit 7abd85796e
5 changed files with 32 additions and 27 deletions

View File

@ -0,0 +1,15 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
namespace Ordering.Infrastructure.EntityConfigurations
{
public class BaseConfiguration<TEntity> : IEntityTypeConfiguration<TEntity> where TEntity : Entity
{
public virtual void Configure(EntityTypeBuilder<TEntity> builder)
{
builder.Ignore(b => b.DomainEvents);
builder.HasKey(e => e.Id);
}
}
}

View File

@ -5,17 +5,12 @@ using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
namespace Ordering.Infrastructure.EntityConfigurations namespace Ordering.Infrastructure.EntityConfigurations
{ {
class BuyerEntityTypeConfiguration class BuyerEntityTypeConfiguration : BaseConfiguration<Buyer>
: IEntityTypeConfiguration<Buyer>
{ {
public void Configure(EntityTypeBuilder<Buyer> buyerConfiguration) public override void Configure(EntityTypeBuilder<Buyer> buyerConfiguration)
{ {
buyerConfiguration.ToTable("buyers", OrderingContext.DEFAULT_SCHEMA); buyerConfiguration.ToTable("buyers", OrderingContext.DEFAULT_SCHEMA);
buyerConfiguration.HasKey(b => b.Id);
buyerConfiguration.Ignore(b => b.DomainEvents);
buyerConfiguration.Property(b => b.Id) buyerConfiguration.Property(b => b.Id)
.UseHiLo("buyerseq", OrderingContext.DEFAULT_SCHEMA); .UseHiLo("buyerseq", OrderingContext.DEFAULT_SCHEMA);
@ -36,6 +31,8 @@ namespace Ordering.Infrastructure.EntityConfigurations
var navigation = buyerConfiguration.Metadata.FindNavigation(nameof(Buyer.PaymentMethods)); var navigation = buyerConfiguration.Metadata.FindNavigation(nameof(Buyer.PaymentMethods));
navigation.SetPropertyAccessMode(PropertyAccessMode.Field); navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
base.Configure(buyerConfiguration);
} }
} }
} }

View File

@ -7,16 +7,12 @@ using System;
namespace Ordering.Infrastructure.EntityConfigurations namespace Ordering.Infrastructure.EntityConfigurations
{ {
class OrderEntityTypeConfiguration : IEntityTypeConfiguration<Order> class OrderEntityTypeConfiguration : BaseConfiguration<Order>
{ {
public void Configure(EntityTypeBuilder<Order> orderConfiguration) public override void Configure(EntityTypeBuilder<Order> orderConfiguration)
{ {
orderConfiguration.ToTable("orders", OrderingContext.DEFAULT_SCHEMA); orderConfiguration.ToTable("orders", OrderingContext.DEFAULT_SCHEMA);
orderConfiguration.HasKey(o => o.Id);
orderConfiguration.Ignore(b => b.DomainEvents);
orderConfiguration.Property(o => o.Id) orderConfiguration.Property(o => o.Id)
.UseHiLo("orderseq", OrderingContext.DEFAULT_SCHEMA); .UseHiLo("orderseq", OrderingContext.DEFAULT_SCHEMA);
@ -81,6 +77,9 @@ namespace Ordering.Infrastructure.EntityConfigurations
.WithMany() .WithMany()
// .HasForeignKey("OrderStatusId"); // .HasForeignKey("OrderStatusId");
.HasForeignKey("_orderStatusId"); .HasForeignKey("_orderStatusId");
base.Configure(orderConfiguration);
} }
} }
} }

View File

@ -5,17 +5,12 @@ using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
namespace Ordering.Infrastructure.EntityConfigurations namespace Ordering.Infrastructure.EntityConfigurations
{ {
class OrderItemEntityTypeConfiguration class OrderItemEntityTypeConfiguration : BaseConfiguration<OrderItem>
: IEntityTypeConfiguration<OrderItem>
{ {
public void Configure(EntityTypeBuilder<OrderItem> orderItemConfiguration) public override void Configure(EntityTypeBuilder<OrderItem> orderItemConfiguration)
{ {
orderItemConfiguration.ToTable("orderItems", OrderingContext.DEFAULT_SCHEMA); orderItemConfiguration.ToTable("orderItems", OrderingContext.DEFAULT_SCHEMA);
orderItemConfiguration.HasKey(o => o.Id);
orderItemConfiguration.Ignore(b => b.DomainEvents);
orderItemConfiguration.Property(o => o.Id) orderItemConfiguration.Property(o => o.Id)
.UseHiLo("orderitemseq"); .UseHiLo("orderitemseq");
@ -54,6 +49,8 @@ namespace Ordering.Infrastructure.EntityConfigurations
.UsePropertyAccessMode(PropertyAccessMode.Field) .UsePropertyAccessMode(PropertyAccessMode.Field)
.HasColumnName("PictureUrl") .HasColumnName("PictureUrl")
.IsRequired(false); .IsRequired(false);
base.Configure(orderItemConfiguration);
} }
} }
} }

View File

@ -6,17 +6,12 @@ using System;
namespace Ordering.Infrastructure.EntityConfigurations namespace Ordering.Infrastructure.EntityConfigurations
{ {
class PaymentMethodEntityTypeConfiguration class PaymentMethodEntityTypeConfiguration : BaseConfiguration<PaymentMethod>
: IEntityTypeConfiguration<PaymentMethod>
{ {
public void Configure(EntityTypeBuilder<PaymentMethod> paymentConfiguration) public override void Configure(EntityTypeBuilder<PaymentMethod> paymentConfiguration)
{ {
paymentConfiguration.ToTable("paymentmethods", OrderingContext.DEFAULT_SCHEMA); paymentConfiguration.ToTable("paymentmethods", OrderingContext.DEFAULT_SCHEMA);
paymentConfiguration.HasKey(b => b.Id);
paymentConfiguration.Ignore(b => b.DomainEvents);
paymentConfiguration.Property(b => b.Id) paymentConfiguration.Property(b => b.Id)
.UseHiLo("paymentseq", OrderingContext.DEFAULT_SCHEMA); .UseHiLo("paymentseq", OrderingContext.DEFAULT_SCHEMA);
@ -60,6 +55,8 @@ namespace Ordering.Infrastructure.EntityConfigurations
paymentConfiguration.HasOne(p => p.CardType) paymentConfiguration.HasOne(p => p.CardType)
.WithMany() .WithMany()
.HasForeignKey("_cardTypeId"); .HasForeignKey("_cardTypeId");
base.Configure(paymentConfiguration);
} }
} }
} }