Repository Pattern Standardization of methods

前端 未结 7 1571
天涯浪人
天涯浪人 2021-01-30 02:05

All I am trying to find out the correct definition of the repository pattern.

My original understanding was this (extremely dumbed down)

  • Separate your Busi
7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-30 02:17

    In addition to your generic repository interface (implementation 1) and your variation on the role-specific repository (implementation 2) you can also consider a generic method repository:

    public interface IRepository
    {
        void Save(ENTITY entity) where ENTITY : DomainEntity;
    
        ENTITY Load(Guid id) where ENTITY : DomainEntity;
    
        IQueryable Query() where ENTITY : DomainEntity;
    
        IQueryable Query(IDomainQuery whereQuery)
            where ENTITY : DomainEntity;
    }
    

    This third version comes from this blogpost by Jimmy Bogard, where he also expresses preference for the generic repository interface. I usually follow that with a generic repository baseclass which implements this interface; that way, I only have to implement the stuff that is different for each domain entity.

提交回复
热议问题