net-业务层仓储
作者:网络转载 发布时间:[ 2015/12/15 11:32:03 ] 推荐标签:测试开发技术
6、我们来看下控制器的调用
public ActionResult Index()
{
//1.通过业务接口查询数据
var Ou_UserInfoBLL = DI.SpringHelper.GetObject<IOu_UserInfoBLL>("Ou_UserInfo");
var userInfo= Ou_UserInfoBLL.Login("", "");
//2.加载视图
return View();
}
我每个地方都通过DI.SpringHelper.GetObject<IOu_UserInfoBLL>("Ou_UserInfo");来调用是不是很不方便,那么我们可以来创建一个业务层仓储来统一管理这些对象的创建。
7、IBLL项目,新建T4模板IBLLSession.tt,拷贝之前IDAL中的模板IDALSession过来,稍微修改一下可以了
<#@ 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 = @"..MODELOA.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;
namespace IBLL
{
public partial interface IBLLSession
{
<#
// Emit Entity Types
foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
{#>
I<#=entity.Name#>BLL I<#=entity.Name#>BLL{get;set;}
<#}#>
}
}
8、BLL项目,新建T4模板BLLSession.tt,拷贝之前DAL中的模板DALSession过来,稍微修改一下可以了
<#@ 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 = @"..MODELOA.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 IBLL;
namespace BLL
{
public partial class BLLSession:IBLLSession
{
<#
int index=0;
// Emit Entity Types
foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name))
{
index++;
#>
#region <#=index #> 数据接口 I<#=entity.Name#>BLL
I<#=entity.Name#>BLL i<#=entity.Name#>BLL;
public I<#=entity.Name#>BLL I<#=entity.Name#>BLL{
get
{
if(i<#=entity.Name#>BLL==null)
i<#=entity.Name#>BLL=new <#=entity.Name#>BLL();
return i<#=entity.Name#>BLL;
}
set
{
i<#=entity.Name#>BLL=value;
}
}
#endregion
<#}#>
}
}
9、UI目录下面,添加类库项目Web.Helper,添加对IBLL和DI项目的引用,新建OperateContext.cs
using DI;
using IBLL;
namespace Web.Helper
{
public class OperateContext
{
public static IBLLSession _IBLLSession = SpringHelper.GetObject<IBLLSession>("BLLSession");
}
}
10、修改控制器调用
using IBLL;
using Web.Helper;
public ActionResult Index()
{
var userInfo = OperateContext._IBLLSession.IOu_UserInfoBLL.Login("", "");
//2.加载视图
return View();
}
现在调用起来是不是方便了许多。
本文内容不用于商业目的,如涉及知识产权问题,请权利人联系SPASVO小编(021-61079698-8054),我们将立即处理,马上删除。
相关推荐
编程常用的几种时间戳转换(java .net 数据库).Net中关于相等的问题Asp.net MVC如何对所有用户输入的字符串字段做Trim处理Asp.Net WebForm生命周期的详解.Net开发的两个小技巧asp.net 六大内置对象.Net基础体系和跨框架开发普及Linux使用Jexus托管Asp.Net Core应用程序asp.net登录验证码实现方法ASP.NET自带对象JSON字符串与实体类的转换从 .NET 和 Java 之争谈 IT 行业.Net高效开发之不可错过的实用工具ASP.NET MVC必须知道的那些事!.NET中使用无闪刷新控件时提示框不显示.net开发中要注意的事项Asp.net Core MVC中使用Session

sales@spasvo.com