MVC+LINQToSQL的Repository模式之(五)BLL层实现IOC

 

namespace Service
{
    public class Service<TEntity> : IService<TEntity> where TEntity : class,Entity.IEntity
    {
        private IRepository<TEntity> iRepository = null;
        public Service()
        {
            iRepository = new Repository<TEntity>();
        }
        #region IService<TEntity> 成员

        public TEntity GetModelById(params object[] keyValues)
        {
            return iRepository.Find(keyValues);
        }

        #endregion
    }
}

 

UI层调用的代码如下:

Service.Service<Entity.TEST.UserBases> iService = new Service.Service<Entity.TEST.UserBases>();
           Console.WriteLine(iService.GetModelById("6").Name);

posted @ 2011-11-08 13:40  张占岭  阅读(2106)  评论(0编辑  收藏  举报