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);

本文转自博客园张占岭(仓储大叔)的博客,原文链接:MVC+LINQToSQL的Repository模式之(五)BLL层实现IOC,如需转载请自行联系原博主。

时间: 2024-09-20 07:38:36

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

MVC+LINQToSQL的Repository模式之(三)Repository模式实现统一CURD操作,实现EF中的Find主键查找

namespace Data.TEST { /// <summary> /// 数据通用操作实现 /// </summary> /// <typeparam name="TEntity"></typeparam> public class Repository<TEntity> : TESTRepositoryBase, IRepository<TEntity> where TEntity : class,IEnt

MVC+LINQToSQL的Repository模式之(二)数据基类

namespace Data.TEST{    /// <summary>    /// 数据操作基类    /// </summary>    public abstract class TESTRepositoryBase    {        /// <summary>        /// 数据库基类        /// </summary>        protected Entity.TEST.LinqTESTDataContext _db

MVC+LINQToSQL的Repository模式之(四)数据统一更新的附加类

namespace public static class DynamicQueryable public static IQueryablethis IQueryablestring params objectreturn IQueryableIQueryablepublic static IQueryable this IQueryable string params objectif nullthrow new ArgumentNullException"source"if nu

Repository模式介绍汇总

1.Linq To Sql中Repository模式应用场景 http://www.cnblogs.com/zhijianliutang/archive/2012/02/24/2367305.html http://tech.it168.com/a2011/1214/1288/000001288218_2.shtml http://git.oschina.net/kuiyu/Repository-Demo 2.分享基于Entity Framework的Repository模式设计 http://

在ASP.NET中实现MVC模式(五)

asp.net 在ASP.NET中实现Model-View-Controller模式(五) 测试 将模型部分从ASP.NET环境中分离出来能够使模型部分更容易的被测试.在ASP.NET环境中进行测试的话,你必须同时测试很多方面,如HTML代码是否正确,而读取HTML代码的工作是非常烦闷的.将模型部分分离出来,使你能够对模型部分做单独的单元测试.下面是NUnit (http://nunit.org)对模型部分进行单元测试的例子. using System; using NUnit.Framewor

关于Repository模式

原文:关于Repository模式 定义(来自Martin Fowler的<企业应用架构模式>): Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects. 个人理解:Repository是一个独立的层,介于领域层与数据映射层(数据访问层)之间.它的存在让领域层感觉不到数据访问层的存在,它提供一个类似集合的接口提供给领域层

使用Repository模式支持产品的客户化

  本篇博客简单描述了Repository模式在OEA中的应用. 不使用Repository时的问题     OEA框架中使用了DDD的思想,面向领域对象进行开发.在DDD中,有很多重要的概念,例如:聚合实体对象.值对象.仓储.工厂.服务等.(不太了解的Repository和DDD的朋友,可以看Evans写的<Domain Driven Design>.)     在OEA中,实体的实现框架使用了CSLA分布式框架.原来为了简单并保持和CSLA开发模式的兼容,一直都把实体的获取模式直接以静态方

Extjs4使用mvc模式,封装Store层的ArrayStore无法动态加载后台数据

问题描述 Extjs4使用mvc模式,封装Store层的ArrayStore无法动态加载后台数据 store层代码 Ext.define('Desktop.store.function.FunctionStore'{ extend: 'Ext.data.ArrayStore' requires:['Desktop.model.function.UserModel'] model: 'Desktop.model.function.UserModel' autoLoad: true proxy:{

Entity Framework Repository模式

原文:Entity Framework Repository模式 Repository模式之前 如果我们用最原始的EF进行设计对每个实体类的"C(增加).R(读取).U(修改).D(删除)"这四个操作. 第一个:先来看看查询,对于实体类简单的查询操作,每次都是这样的过程会在代码中拥有大量的重复 极为类似的代码段. using (var db = new EFContext("EFContext")) { var persons = db.Persons.Where(