代码改变世界

仓储类小议

2011-02-12 19:49  血糯米Otomii  阅读(232)  评论(0编辑  收藏  举报

Repository.cs 为仓储提供公共方法的父类,用于总领整个领域驱动模型,用于对于NO业务限制所以操作,最简单的就是增删改查,基本就是集成到这个仓储类中,进行统一的解析和执行

Business.cs为Bean类

IBusinessRepository.cs为接口业务方法附加类

BusinessRepositoryImpl.cs为业务方法的实现类

 

    /// <summary>
    /// Repository  For All Repository
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class Repository<T> where T : class
    {
        /// <summary>
        /// Find an instance with predicate
        /// </summary>
        /// <param name="predicate">predicate</param>
        /// <returns>An instance of class T</returns>
         T FindForSingle(Func<T, bool> predicate)
        {
            return FindAll().Where(predicate).FirstOrDefault();
        }

         /// <summary>
         /// Find matched instances with predicate
         /// </summary>
         /// <param name="predicate">predicate</param>
         /// <returns>An instance of class T</returns>
         IEnumerable<T> FindForMatch(Func<T, bool> predicate)
         {
             return FindAll().Where(predicate);
         }

        /// <summary>
        /// Find all instances
        /// </summary>
        /// <returns></returns>
        IEnumerable<T> FindAll()
        {
            return new List<T>();
        }

        /// <summary>
        /// Save an instance
        /// </summary>
        /// <param name="instance"></param>
        void Save(T instance)
        {
           
        }

        /// <summary>
        /// Insert an instance
        /// </summary>
        /// <param name="instance"></param>
        void Insert(T instance)
        {
           
        }

        /// <summary>
        /// Update an instance
        /// </summary>
        /// <param name="instance"></param>
        void Update(T instance)
        {
           
        }
    }

    public class Business{}

    /// <summary>
    /// IBusinessRepository For Its Own
    /// </summary>
    public interface IBusinessRepository
    {
        /// <summary>
        /// Proccess for business
        /// </summary>
        void Proccess();
    }

    public class BusinessRepositoryImpl:Repository<Business>,IBusinessRepository
    {
        public void Proccess()
        {
           
        }
    }