Asp.Net mvc4 +Spring (提出注入的bll层对象,单独一个xml文件)
将BLL层注入的对象分离出来,和UI注入对象放在一起不太友好
在Bll类库下建所有实体的注入对象,既TT模板
<#@ 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 = @"..\\My.OADemo.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"> <# // Emit Entity Types foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name)) { //fileManager.StartNewFile(entity.Name + "RepositoryExt.cs"); //BeginNamespace(namespaceName, code); #> <object id="<#=entity.Name#>Service" type="My.OADemo.BLL.<#=entity.Name#>Service, My.OADemo.BLL" > </object> <#}#> </objects>
将生成的代码复制到ui层新建的xml文件中
然后在web.config文件中添加这个文件的路径信息