I have a couple of derived classes Shippable
and Downloadable
inheriting from the same base class Product
and each of them have own properties:
public abstract class Product : Entity<Guid>
{
public ProductType ProductType{ get; set; }
public string Name { get; set; }
}
public class Downloadable : Product
{
public Guid DownloadId { get; set; }
}
public class Shippable : Product
{
public Guid ShippingInfo { get; set; }
}
I used EF Core TBH design for my DataTable so all properties of this entities stored in a table:
builder.Entity<Product>(
b =>
{
b.ToTable(
options.TablePrefix + "Products",
options.Schema
);
b.HasKey(
x => x.Id
);
b.HasDiscriminator<ProductType>(
nameof(Product.ProductType)
)
.HasValue<Downloadable>(
ProductType.Downloadable
)
.HasValue<Shippable>(
ProductType.Shippable
);
}
My project is NLayered DDD so I have a application layer which produce business logics for UI/REST API methods and contains application services and DTOs.
My question is whats the best practice for apply this. What you think about this options:
1- Business services per derived class with derived DTOs
2- Only one service that can serve all with shared DTO (contains nullable properties of derived classes
3- Your suggestions
Thanks in advance.