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();
  }
  现在调用起来是不是方便了许多。