【这里是的实现,指的是针对各个数据访问框架的一个基础实现】

目标

  •   定义仓储/QueryEntry的基本功能
  •   实现仓储的基本功能,以利于复用
  •   实现一些常用的功能
  •   提供一些便利的功能

目标框架

博主使用的ORM框架是EF6.x,使用MAP来配置模型和数据库之间的映射(因为模型是定义在领域层[CQRS]的),所以不打算使用声明式的Attribute。使用code first来生成数据库。

仓储基本功能

使用一个泛型接口定义了一个仓储需要实现的功能:

public interface IBasicReponsitory<T>
    {
        void Insert(T item);
        void Delete(T item);
        void Delete(Guid aggregateId);
        void Update(T category);
        T Fetch(Guid aggregateId);
        T TryFetch(Guid aggregateId);
        bool Exists(Expression<Func<T, bool>> predict);

        /*以下是额外的一些接口方法,待商榷*/
        IQueryable<T> Query();
        Task<T> FetchAsync(Guid id);
        Task<T> TryFetchAsync(Guid id);
        Task<IEnumerable<T>> RetriveAsync(Expression<Func<T, bool>> predict);
    }
View Code

相关文章:

  • 2022-02-02
  • 2021-10-20
  • 2021-09-14
  • 2021-06-08
  • 2021-11-12
  • 2021-12-22
  • 2022-02-19
  • 2021-07-15
猜你喜欢
  • 2021-08-16
  • 2021-09-01
  • 2022-01-08
  • 2021-08-28
  • 2021-08-08
  • 2022-12-23
相关资源
相似解决方案