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. API Authentication Error: {"error":"invalid_client","message":"Client authentication failed"}

    解决方法:https://github.com/laravel/passport/issues/221 In your oauth_clients table, do the values you h ...

  2. 【Asp.net入门07】第一个ASP.NET 应用程序-创建数据模型和存储库

    1.理解概念 先理解一下两个概念. 模型 模型是指数据的结构类型,以及可调用的方法.对面向对象编程方法来说,其实就是类.模型类就是一个描述数据的类.只有把数据按一定方式描述出来,我们才能在程序中方便地 ...

  3. 安装并使用 Wowza 发布你的 RTMP 直播流

    转载自:http://blog.csdn.net/defonds/article/details/11979095 I. 下载 Wowza         官方下载地址 http://www.wowz ...

  4. bootstrap-switch

    首先需要引入bootstrap的css和js文件,再引入bootstrap-switch.css和bootstrap-switch.js文件 <script type="text/ja ...

  5. windows安装filebeat服务报错

    cmd进入filebeat目录下   用以下命令执行: PowerShell.exe -ExecutionPolicy UnRestricted -File .\install-service-fil ...

  6. Java并发编程原理与实战八:产生线程安全性问题原因(javap字节码分析)

    前面我们说到多线程带来的风险,其中一个很重要的就是安全性,因为其重要性因此,放到本章来进行讲解,那么线程安全性问题产生的原因,我们这节将从底层字节码来进行分析. 一.问题引出 先看一段代码 packa ...

  7. #Fixed# easy-animation | Animation for Sass

    原文链接:http://www.cnblogs.com/maplejan/p/3659830.html 主要修复3.4版本后变量作用域的问题. 代码如下: /* easy-animation.scss ...

  8. input限制

    转载,暂未使用,可以借鉴. 出处:http://blog.csdn.net/a13590394462/article/details/73943785

  9. JavaScript的基本介绍

    JavaScript入门介绍 输出语句:document.write()   1.执行顺序:从上到下,每一天语句是要加分号的,如果不加的话,浏览器会默认帮你自动添加,分号.   2.注释:一行注释就是 ...

  10. 45、文件过滤器FilenameFilter

    文件过滤器FilenameFilter JDK中提供了一个FilenameFilter的接口用来实现文件过滤功能,可以使用这个文件过滤器来实现上一节中的问题. File类中有一个带参数的list方法 ...