Abp Test polymerization

 

Examples of the official website start tutorial Abp is IRpositoty <entity> directly in the application layer. But if the will is an aggregate root that right? Well aggregate root access is the smallest unit of storage to operate the service through aggregate root, is an entity, then the entity additions and deletions to change search, it should be in aggregate root inside.

That there is a problem, inherited the aggregate root entity ,, he did not warehousing, how to save it?

Method One: dependency injection, this will not work, so that database migration was 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 Two: inherited storage interfaces,
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;
        }
}

 

   This problem is the application layer how to call it? The application layer is to appear warehouse.
 Method three: effect polymerization root interface, inheritance and Storage: Test2 is in the 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();
        }
    }

 So that the compiler is not the past, because EF Test2Repository in that layer, while the Core who is not dependent, at the bottom, this is not going to work.

 

Method four: this is the root of the polymer, and then implement a IOrder interfaces, storage interfaces, and this interface there is an overlap in the application layer, the exposed IOrder interfaces on the line.

  IOrder can be injected into the application layer dependent, since he is the postfix Order.
  When a generic method call and to be passed as the type (parameters or return values)
      This execution, has not been saved,
3 above is not feasible, the following method may have
Success Method a: injection property using it. Note that, the polymerization should root dependency on the injection frame. This example is Test
       IocManager.Register<Test>(DependencyLifeStyle.Transient);
 
 
 

Guess you like

Origin www.cnblogs.com/qgbo/p/11261301.html