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及工厂模式相关的 ...
随机推荐
- Java基础-IO流对象之随机访问文件(RandomAccessFile)
Java基础-IO流对象之随机访问文件(RandomAccessFile) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.RandomAccessFile简介 此类的实例支持对 ...
- svn服务器搭建(windows)
转载:https://blog.csdn.net/daobantutu/article/details/60467185 本教程会从最基本的下载安装到上传代码,下载代码这条线来详细讲述如何完成SVN服 ...
- HTTP 错误 500.19 请求的页面的相关配置数据无效 解决办法
"HTTP 错误 500.19 请求的页面的相关配置数据无效" 解决办法 HTTP 错误 500.19 - Internal Server Error无法访问请求的页面,因为该 ...
- bzoj千题计划129:bzoj2007: [Noi2010]海拔
http://www.lydsy.com/JudgeOnline/problem.php?id=2007 1.所有点的高度一定在0~1之间, 如果有一个点的高度超过了1,那么必定会有人先上坡,再下坡, ...
- Backbone基础笔记
之前做一个iPad的金融项目的时候有用到Backbone,不过当时去的时候项目已经进入UAT测试阶段了,就只是改了改Bug,对Backbone框架算不上深入了解,但要说我一点都不熟悉那倒也不是,我不太 ...
- python核心编程笔记——Chapter7
Chapter7.映像和集合类型 最近临到期末,真的被各种复习,各种大作业缠住,想想已经荒废了python的学习1个月了.现在失去了昔日对python的触觉和要写简洁优雅代码的感觉,所以临到期末毅然继 ...
- Linux ftp命令的使用方法 -- 转
http://jingyan.baidu.com/article/066074d68b6a7ac3c21cb038.html FTP(File Transfer Protocol, FTP)是TCP/ ...
- getElementById()方法取值
举例子: javascript: var time = document.getElementById('jidu').value; //指定时间 var taskclass = document.g ...
- ASP.NET 应用生命周期19个事件简介
下面是请求管道中的19个事件. (1)BeginRequest: 开始处理请求 (2)AuthenticateRequest授权验证请求,获取用户授权信息 (3):PostAuthenticateRe ...
- 写给“有钱大爷”、”美工殿下”、“前端文艺青年”的微信HTML5页面设计建议
============================== 2018更新 iphone X 的设计内容 ============================== 我保证你一分钟就 ...