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代替抽象工厂(三)的更多相关文章

  1. 深入浅出设计模式——抽象工厂模式(Abstract Factory)

    模式动机在工厂方法模式中具体工厂负责生产具体的产品,每一个具体工厂对应一种具体产品,工厂方法也具有唯一性,一般情况下,一个具体工厂中只有一个工厂方法或者一组重载的工厂方法.但是有时候我们需要一个工厂可 ...

  2. iOS常用设计模式——工厂方法(简单工厂模式,工厂方法模式, 抽象工厂模式)

    1. 简单工厂模式 如何理解简单工厂,工厂方法, 抽象工厂三种设计模式? 简单工厂方法包含:父类拥有共同基础接口,具体子类实现子类特殊功能,工厂类根据参数区分创建不同子类实例.该场景对应的UML图如下 ...

  3. iOS经常使用设计模式——工厂方法(简单工厂模式,工厂方法模式, 抽象工厂模式)

    1. 简单工厂模式 怎样理解简单工厂,工厂方法. 抽象工厂三种设计模式? 简单工厂的生活场景.卖早点的小摊贩.他给你提供包子,馒头,地沟油烙的煎饼等,小贩是一个工厂.它生产包子,馒头,地沟油烙的煎饼. ...

  4. Java设计模式(三) 抽象工厂模式

    原创文章,同步发自作者个人博客,转载请注明出处 http://www.jasongj.com/design_pattern/abstract_factory/ 抽象工厂模式解决的问题 上文<工厂 ...

  5. 简单工厂模式,工厂方法模式,抽象工厂模式,spring的狂想

    菜鸟D在项目中遇见一个比较纠结的高耦合,所以就想办法来解耦.情况是这样的:系统通过用户选择treeview控件的节点判断调用不同的处理,这些处理中某些东西又是类似的.同事的建议是采用简单工厂,耦合就耦 ...

  6. java之设计模式工厂三兄弟之抽象工厂模式

    [学习难度:★★★★☆,使用频率:★★★★★]  工厂方法模式通过引入工厂等级结构,解决了简单工厂模式中工厂类职责太重的问题,但由于工厂方法模式中的每个工厂只生产一类产品,可能会导致系统中存在大量的工 ...

  7. Java 设计模式之抽象工厂模式(三)

    原文地址:Java 设计模式之抽象工厂模式(三) 博客地址:http://www.extlight.com 一.前言 上篇文章 <Java 设计模式之工厂模式(二)>,介绍了简单工厂模式和 ...

  8. PHP设计模式(三)抽象工厂模式(Abstract Factory For PHP)

    一.什么是抽象工厂模式 抽象工厂模式的用意为:给客户端提供一个接口,可以创建多个产品族中的产品对象 ,而且使用抽象工厂模式还要满足以下条件: 系统中有多个产品族,而系统一次只可能消费其中一族产品. 同 ...

  9. .NET抽象工厂模式微理解--教你在项目中实现抽象工厂

    .NET抽象工厂模式微理解--教你在项目中实现抽象工厂 最近在学习MVC,对于MVC里面的一些项目上的东西都和抽象模式有关,今天就微说明一下个人对于抽象工厂模式的理解,以方便学习MVC及工厂模式相关的 ...

随机推荐

  1. Chapter1(预科)--C++Prime笔记

    心得体会: 因为之前一直在用在学C,因此在看完C++Prime第一章后,就有中在一个培训班中,一个老师用一个简单的项目来带你了解这种语言的特性的感觉.当然这个告诉是在让你脑子固化接受一些点的前提下. ...

  2. 第一天:简单工厂模式与UML类图

    何为简单工厂模式:     通过专门定义一个类,来负责创建其他类的实例,这些其它类通常具有共同的父类.   简单工厂模式的UML类图:       简单工厂模式中包含的角色和相应的职责如下:     ...

  3. Python 装饰器(进阶篇)

    装饰器是什么呢? 我们先来打一个比方,我写了一个python的插件,提供给用户使用,但是在使用的过程中我添加了一些功能,可是又不希望用户改变调用的方式,那么该怎么办呢? 这个时候就用到了装饰器.装饰器 ...

  4. NLP分词

    英文分词: #英文分词 import nltk sentence="hello,world" tokens=nltk.word_tokenize(sentence) print(t ...

  5. java8 新特性 Stream

    1. Stream初体验 我们先来看看Java里面是怎么定义Stream的: A sequence of elements supporting sequential and parallel agg ...

  6. [Java] 理解JVM之一:工作机制及基本结构

    一.基本结构 类加载器:在 JVM 启动时或在类运行时需要将类的字节码信息加载到 JVM 内存区域中. 执行引擎:负责执行字节码信息中包含的字节码指令,相当于实际机器上的 CPU. 内存区域:也被称为 ...

  7. html基础知识汇总(二)之Emmet语法

    div.imageBox+div.infoBox+input[type="button" class="starBtn"]*3 <div class=&q ...

  8. 图论:LCA-欧拉序

    #include<cmath> #include<vector> #include<cstdio> #include<cstring> #include ...

  9. sql 存储时空格转成问号问题

    最近做系统,从邮件中导出邮件,上传到系统中,遇到一个奇葩的问题,如下: 通过本地文件看,文件名中是一个空格,上传至数据库后,展示就变成了问号,究其原因,发现是一个特殊字符导致: 最近认真去查了一下这个 ...

  10. 微信小程序开发(五)开发框架MINA

    微信团队为小程序提供的框架命名为MINA应用框架.MINA框架通过封装微信客户端提供的文件系统.网络通信.任务管理.数据安全等基础功能,对上层提供一整套JavaScript API,让开发者能够非常方 ...