An example of the tutorial that Abp started with is that IRpository < entity > appears directly in the application layer. But if it's an aggregate root, it's the smallest unit to access the warehouse. To operate the business through the aggregate root, it's the entity, so the addition, deletion and modification of the entity should also be in the aggregate root.
So there's a problem. Entities inherit aggregate roots. They don't have warehouses. How do they keep them?
Method 1: Dependency injection, which is not feasible, so the database migration is unsuccessful.
1 public class Order :AggregateRoot, IRepository<Order>, ICreationAudited 2 { 3 [NotMapped] 4 private IRepository<Order> _repository { get; set; } 5 public Order(IRepository<Order> repository) 6 { 7 _repository = repository; 8 } 9 public long? CreatorUserId { get; set; } 10 public DateTime CreationTime { get; set ; } 11 public List<OrderItem> OrderItem { get; set; } 12 public string Remark { get; set; } 13 public Address Address { get; set; } 14 15 public Order Insert(Order entity) 16 { 17 return entity; 18 } 19 }
public class Order :AggregateRoot, IRepository<Order>, ICreationAudited { public long? CreatorUserId { get; set; } public DateTime CreationTime { get; set ; } public List<OrderItem> OrderItem { get; set; } public string Remark { get; set; } public Address Address { get; set; } public Order Insert(Order entity) { return entity; } }
public class Test2 : Test2Repository, IAggregateRoot, ICreationAudited { public long? CreatorUserId { get; set; } public DateTime CreationTime { get; set; } public string Remark { get; set; } public ICollection<IEventData> DomainEvents => throw new NotImplementedException(); public int Id { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public bool IsTransient() { throw new NotImplementedException(); } }
This compilation is not going to work because Test2Repository is on the EF level, and Core is not dependent on anyone, and at the bottom, this is not feasible.
Method 4: This aggregation root is used to implement an IOrder interface, which overlaps with the storage interface. In the application layer, it is enough to expose the IOrder interface.