基本信息
源码名称:基于EF+WCF的通用三层架构 含解析 附源码
源码大小:0.46M
文件格式:.rar
开发语言:C#
更新时间:2013-03-13
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
工厂实现了RemoteServiceFactory(用于远程调用)和RefServiceFactory(本地引用调用服务层)生成客户端代理,都需要实现IServiceFactory的“IService CreateService();”
RemoteServiceFactory通过ChannelFactory动态产生客户端代理类IService,并将此对象进行缓存
WCFExtension实现了WCFContext,可传输用户登陆或IP上下文信息,以及拦截方法写Log的机制
本项目结合EF 4.3及WCF实现了经典三层架构,各层面向接口,WCF实现SOA,Repository封装调用,在此基础上实现了WCFContext,动态服务调用及一个分页的实例。
项目架构:
在传统的三层架构上增加了WcfService(服务端),WcfClientProxy(客户端服务调用),及WcfExtension(一些扩展)
数据层Repository的实现:
View Code public class DaoBase : IRepository, IDisposable { public DbContext context; public DaoBase() { this.context = new EasyEF.DAL.DbContext(); } public T Update<T>(T entity) where T : class { var set = context.Set<T>(); set.Attach(entity); context.Entry<T>(entity).State = EntityState.Modified; context.SaveChanges(); return entity; } public T Insert<T>(T entity) where T : class { context.Set<T>().Add(entity); context.SaveChanges(); return entity; } public void Delete<T>(T entity) where T : class { context.Entry<T>(entity).State = EntityState.Deleted; context.SaveChanges(); } public T Find<T>(params object[] keyValues) where T : class { return context.Set<T>().Find(keyValues); } public List<T> FindAll<T>(Expression<Func<T, bool>> conditions = null) where T : class { if (conditions == null) return context.Set<T>().ToList(); else return context.Set<T>().Where(conditions).ToList(); } public PagedList<T> FindAllByPage<T, S>(Expression<Func<T, bool>> conditions, Expression<Func<T, S>> orderBy, int pageSize, int pageIndex) where T : class { var queryList = conditions == null ? context.Set<T>() : context.Set<T>().Where(conditions) as IQueryable<T>; return queryList.OrderByDescending(orderBy).ToPagedList(pageIndex, pageSize); } public void Dispose() { this.context.Dispose(); }