zoukankan      html  css  js  c++  java
  • 仓储类小议

    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()
            {
               
            }
        }

  • 相关阅读:
    通过AIR Native Extension在AIR应用中加入iAd广告(一) —— Flash Builder篇
    使用MonoTouch.SQLite简化用户界面开发
    常见的几种分支开发方式
    给对象增加一个简单的自定义事件机制
    WCF 4.5:配置文件更小,对ASP.NET的支持更好
    MongoDB中的Group By
    SQL Server 2012大幅增强了TSQL
    编程珠玑:对DAO层的一点修改
    《The Elements of User Experience》读书笔记
    ORM工具LLBLGen Pro 3.5发布
  • 原文地址:https://www.cnblogs.com/otomii/p/1952782.html
Copyright © 2011-2022 走看看