OA项目Spring.Net代替抽象工厂(三)
Servrvice层的代码:
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"> <object name="UserInfoService" type="SunOA.BLL.UserInfoService, SunOA.BLL" singleton="false" >
<property name="DbSession" ref="DbSession" />
<property name="CurrentDal" ref="UserInfoDal" /> <!--<constructor-arg index="0" ref="DbSession" />-->
</object>
<object name="OrderInfoService" type="SunOA.BLL.OrderInfoService, SunOA.BLL" singleton="false" >
<property name="DbSession" ref="DbSession" /> <property name="CurrentDal" ref="OrderInfoDal" />
<!--构造函数注入-->
<!--<constructor-arg index="0" ref="DbSession" />-->
</object>
</objects>
Dal层代码:
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"> <!--<object name="DbSessionFactory" type="SunOA.DALFactory.DbSessionFactory,SunOA.DALFactory " singleton="true" >
</object>--> <!--spring.net 通过工厂的实例方法来创建对象的配置demo-->
<!--<object name="DbSession" type="SunOA.DALFactory.DbSession, SunOA.DALFactory" singleton="false" factory-method="GetCurrentDbSession" factory-object="DbSessionFactory" >
</object>--> <!--spring.net 通过工厂的一个静态方法来创建对象的 配置demo。 type就直接配置到工厂类型就可以了。-->
<object name="DbSession" type="SunOA.DALFactory.DbSessionFactory, SunOA.DALFactory" singleton="false" factory-method="GetCurrentDbSession" >
</object>
<object name="OrderInfoDal" type="SunOA.EFDAL.OrderInfoDal, SunOA.EFDAL" singleton="false" >
</object>
<object name="UserInfoDal" type="SunOA.EFDAL.UserInfoDal, SunOA.EFDAL" singleton="false" >
</object> </objects>
获取数据库的所有表:
exec sp_tables
拿到表中的列:
exec sp_columns users
查看数据库名称:
exec sp_databases
T4模板的使用:
SunOA.IDAL下:IDals
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#><#@
output extension=".cs"#> <# CodeGenerationTools code = new CodeGenerationTools(this);
MetadataLoader loader = new MetadataLoader(this);
CodeRegion region = new CodeRegion(this, 1);
MetadataTools ef = new MetadataTools(this); string inputFile = @"..\\SunOA.Model\\DataModel.edmx"; EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);
string namespaceName = code.VsNamespaceSuggestion(); EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this); #>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SunOA.Model; namespace SunOA.IDAL
{ <#
foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
{ #>
public partial interface I<#=entity.Name#>Dal : IBaseDal<<#=entity.Name#>>
{
}
<#}#> }
IDbSession.tt
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#><#@
output extension=".cs"#> <# CodeGenerationTools code = new CodeGenerationTools(this);
MetadataLoader loader = new MetadataLoader(this);
CodeRegion region = new CodeRegion(this, 1);
MetadataTools ef = new MetadataTools(this); string inputFile = @"..\\SunOA.Model\\DataModel.edmx"; EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);
string namespaceName = code.VsNamespaceSuggestion(); EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this); #>
namespace SunOA.IDAL
{
public partial interface IDbSession
{ <#
foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
{ #>
I<#=entity.Name#>Dal <#=entity.Name#>Dal { get;}
<#}#>
} }
SunOA.EFDAL.Dals
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#><#@
output extension=".cs"#> <# CodeGenerationTools code = new CodeGenerationTools(this);
MetadataLoader loader = new MetadataLoader(this);
CodeRegion region = new CodeRegion(this, 1);
MetadataTools ef = new MetadataTools(this); string inputFile = @"..\\SunOA.Model\\DataModel.edmx"; EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);
string namespaceName = code.VsNamespaceSuggestion(); EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this); #>
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using SunOA.IDAL;
using SunOA.Model; namespace SunOA.EFDAL
{ <#
foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
{ #>
public partial class <#=entity.Name#>Dal:BaseDal<<#=entity.Name#>>,I<#=entity.Name#>Dal
{
}
<#}#> }
DbSession.tt
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#><#@
output extension=".cs"#> <# CodeGenerationTools code = new CodeGenerationTools(this);
MetadataLoader loader = new MetadataLoader(this);
CodeRegion region = new CodeRegion(this, 1);
MetadataTools ef = new MetadataTools(this); string inputFile = @"..\\SunOA.Model\\DataModel.edmx"; EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);
string namespaceName = code.VsNamespaceSuggestion(); EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this); #>
using SunOA.EFDAL;
using SunOA.IDAL; namespace SunOA.DALFactory
{
public partial class DbSession :IDbSession
{ <#
foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
{ #>
public I<#=entity.Name#>Dal <#=entity.Name#>Dal
{
get { return StaticDalFactory.Get<#=entity.Name#>Dal(); }
}
<#}#>
}
}
StaticDalFactory
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#><#@
output extension=".cs"#> <# CodeGenerationTools code = new CodeGenerationTools(this);
MetadataLoader loader = new MetadataLoader(this);
CodeRegion region = new CodeRegion(this, 1);
MetadataTools ef = new MetadataTools(this); string inputFile = @"..\\SunOA.Model\\DataModel.edmx"; EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);
string namespaceName = code.VsNamespaceSuggestion(); EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this); #>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using SunOA.EFDAL;
using SunOA.IDAL;
using SunOA.NHDAL; namespace SunOA.DALFactory
{ public partial class StaticDalFactory
{ <#
foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
{ #>
public static I<#=entity.Name#>Dal Get<#=entity.Name#>Dal()
{
return Assembly.Load(assemblyName).CreateInstance(assemblyName + ".<#=entity.Name#>Dal")
as I<#=entity.Name#>Dal;
}
<#}#>
}
}
IBLL.IServices
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#><#@
output extension=".cs"#> <# CodeGenerationTools code = new CodeGenerationTools(this);
MetadataLoader loader = new MetadataLoader(this);
CodeRegion region = new CodeRegion(this, 1);
MetadataTools ef = new MetadataTools(this); string inputFile = @"..\\SunOA.Model\\DataModel.edmx"; EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);
string namespaceName = code.VsNamespaceSuggestion(); EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this); #>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SunOA.Model; namespace SunOA.IBLL
{
<#
foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
{ #>
public partial interface I<#=entity.Name#>Service:IBaseService<<#=entity.Name#>>
{
}
<#}#>
}
IBLL.ServerXmlSpring
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#><#@
output extension=".xml"#><# CodeGenerationTools code = new CodeGenerationTools(this);
MetadataLoader loader = new MetadataLoader(this);
CodeRegion region = new CodeRegion(this, 1);
MetadataTools ef = new MetadataTools(this); string inputFile = @"..\\SunOA.Model\\DataModel.edmx"; EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);
string namespaceName = code.VsNamespaceSuggestion(); EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this); #><?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<#
foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
{ #>
<object name="<#=entity.Name#>Service" type="SunOA.BLL.<#=entity.Name#>Service, SunOA.BLL" singleton="false" >
</object>
<#}#>
</objects>
BLL.Services
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#><#@
output extension=".cs"#> <# CodeGenerationTools code = new CodeGenerationTools(this);
MetadataLoader loader = new MetadataLoader(this);
CodeRegion region = new CodeRegion(this, 1);
MetadataTools ef = new MetadataTools(this); string inputFile = @"..\\SunOA.Model\\DataModel.edmx"; EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);
string namespaceName = code.VsNamespaceSuggestion(); EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this); #>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SunOA.DALFactory;
using SunOA.EFDAL;
using SunOA.IBLL;
using SunOA.IDAL;
using SunOA.Model;
using SunOA.NHDAL; namespace SunOA.BLL
{
<#
foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
{ #>
public partial class <#=entity.Name#>Service:BaseService<<#=entity.Name#>>,I<#=entity.Name#>Service //crud
{
public override void SetCurrentDal()
{
CurrentDal = DbSession.<#=entity.Name#>Dal;
}
}
<#}#>
}
添加类的时候,生成转换所有的T4模板。
OA项目Spring.Net代替抽象工厂(三)的更多相关文章
- 深入浅出设计模式——抽象工厂模式(Abstract Factory)
模式动机在工厂方法模式中具体工厂负责生产具体的产品,每一个具体工厂对应一种具体产品,工厂方法也具有唯一性,一般情况下,一个具体工厂中只有一个工厂方法或者一组重载的工厂方法.但是有时候我们需要一个工厂可 ...
- iOS常用设计模式——工厂方法(简单工厂模式,工厂方法模式, 抽象工厂模式)
1. 简单工厂模式 如何理解简单工厂,工厂方法, 抽象工厂三种设计模式? 简单工厂方法包含:父类拥有共同基础接口,具体子类实现子类特殊功能,工厂类根据参数区分创建不同子类实例.该场景对应的UML图如下 ...
- iOS经常使用设计模式——工厂方法(简单工厂模式,工厂方法模式, 抽象工厂模式)
1. 简单工厂模式 怎样理解简单工厂,工厂方法. 抽象工厂三种设计模式? 简单工厂的生活场景.卖早点的小摊贩.他给你提供包子,馒头,地沟油烙的煎饼等,小贩是一个工厂.它生产包子,馒头,地沟油烙的煎饼. ...
- Java设计模式(三) 抽象工厂模式
原创文章,同步发自作者个人博客,转载请注明出处 http://www.jasongj.com/design_pattern/abstract_factory/ 抽象工厂模式解决的问题 上文<工厂 ...
- 简单工厂模式,工厂方法模式,抽象工厂模式,spring的狂想
菜鸟D在项目中遇见一个比较纠结的高耦合,所以就想办法来解耦.情况是这样的:系统通过用户选择treeview控件的节点判断调用不同的处理,这些处理中某些东西又是类似的.同事的建议是采用简单工厂,耦合就耦 ...
- java之设计模式工厂三兄弟之抽象工厂模式
[学习难度:★★★★☆,使用频率:★★★★★] 工厂方法模式通过引入工厂等级结构,解决了简单工厂模式中工厂类职责太重的问题,但由于工厂方法模式中的每个工厂只生产一类产品,可能会导致系统中存在大量的工 ...
- Java 设计模式之抽象工厂模式(三)
原文地址:Java 设计模式之抽象工厂模式(三) 博客地址:http://www.extlight.com 一.前言 上篇文章 <Java 设计模式之工厂模式(二)>,介绍了简单工厂模式和 ...
- PHP设计模式(三)抽象工厂模式(Abstract Factory For PHP)
一.什么是抽象工厂模式 抽象工厂模式的用意为:给客户端提供一个接口,可以创建多个产品族中的产品对象 ,而且使用抽象工厂模式还要满足以下条件: 系统中有多个产品族,而系统一次只可能消费其中一族产品. 同 ...
- .NET抽象工厂模式微理解--教你在项目中实现抽象工厂
.NET抽象工厂模式微理解--教你在项目中实现抽象工厂 最近在学习MVC,对于MVC里面的一些项目上的东西都和抽象模式有关,今天就微说明一下个人对于抽象工厂模式的理解,以方便学习MVC及工厂模式相关的 ...
随机推荐
- matlab --- plot画图
plot画的图形在上一个plot的figure中:hold on 添加图例:legend({'X','Y'}) 限制X轴Y轴的坐标范围:xlim([380 780]);ylim([0 2]) 或 ax ...
- Java基础-StringBuffer类与StringBuilder类简介
Java基础-StringBuffer类与StringBuilder类简介 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.StringBuffer类 在学习过String类之后 ...
- zz 启动Matlab提示Microsoft Visual C++ 2005 Redistributable存在问题问题
帮助领导搞Matlab 2010a 绿色版; 领导把绿色版的文件夹挪了一下位置 (领导就是领导,做什么都按照自己的想当然的想法做) 然后, 脆弱的绿色版Matlab 2010a Portable就罢工 ...
- 关于thinkpad安装win10操作系统
thinkpad预装的是win8或者win10,会有自己的分区方式是GPT,所以会出现两个引导分区. F2进入tinkpad的bios,F12进入启动选项 我们用pe进入后,用分区工具删除两个分区,然 ...
- c# net 使用反射为对象赋值
public T Bson2T(MongoDB.Bson.BsonDocument bson) { T t = default(T); //获取T类中的所有属性 PropertyInfo[] Tpro ...
- Electron 开发环境下总是 crash
全局安装一个 electron devtool 关掉 崩溃时选择重新打开
- node.js、git、bootstrap等安装配置
纯记录 一,安装node.js 1 官方网址 http://nodejs.org/ 点击install 下载node-v0.10.22-x86.msi 2 安装,修改安装目录到d盘,一路next,无 ...
- 如何编译和安装libevent【转】
转自:http://www.open-open.com/lib/view/open1455522194089.html 来自: http://blog.csdn.net/yangzhenping/ar ...
- DRM/KMS 基本组件介绍
Each DRM device provides access to manage which monitors and displays are currently used and what fr ...
- ArcGIS RunTime Sdk +WPF 基础地图显示
1 简单的地图展示 ArcGISRunTime 的平面地图展示主要依赖MapView这个控件,MapView是地图的容器,Map主要是图层的集合 (注:三维场景的显示主要依赖SceneView这个控件 ...