Abp Polymerization Test

Posted by dragongamer on Wed, 31 Jul 2019 06:05:27 +0200

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 }

 

 
Method 2: Inherit the storage interface.
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;
        }
}

 

The question is how to call the application layer. The application layer still needs warehousing.
Method 3: Implement aggregate root interface and inherit warehouse class: Test2 in code.
 
    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.

IOrder can inject dependencies into the application layer because his postfix is Order.
Generic methods can be passed as types (parameters or return values) when invoked.
This is executed and will not be saved.
The top three are not feasible. Here's a way to do that.
Success Method 1: Use Property Injection. Note that the aggregation root should be placed in the dependency injection framework. This example is Test.
       IocManager.Register<Test>(DependencyLifeStyle.Transient);
 
Source code: https://github.com/qgbo/Abp-
 
 

Topics: PHP Database github