This commit is contained in:
454313500@qq.com
2021-03-23 14:27:59 +08:00
parent b5ed74fabd
commit ea8dd04c8c
7 changed files with 105 additions and 8 deletions

View File

@@ -27,4 +27,23 @@
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<Compile Update="T4Startup.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>T4Startup.tt</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="T4Startup.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>T4Startup.cs</LastGenOutput>
</None>
</ItemGroup>
</Project> </Project>

View File

@@ -56,7 +56,7 @@ namespace CC.Yi.API
{ {
// logging.ClearProviders(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><D0BF><EFBFBD>̨<EFBFBD><CCA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> // logging.ClearProviders(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><D0BF><EFBFBD>̨<EFBFBD><CCA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
}).UseNLog(); }).UseNLog();//<2F><><EFBFBD><EFBFBD>nlog<6F><67>־<EFBFBD><D6BE><EFBFBD><EFBFBD>
} }
} }

View File

@@ -59,13 +59,7 @@ namespace CC.Yi.API
})); }));
} }
//<2F><>̬ <20><><EFBFBD><EFBFBD>AOP˼<50><CBBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2> Autofac
public void ConfigureContainer(ContainerBuilder builder)
{
builder.RegisterType(typeof(CustomAutofacAop));
builder.RegisterGeneric(typeof(BaseDal<>)).As(typeof(IBaseDal<>)) ;
builder.RegisterType<studentBll>().As<IstudentBll>().EnableInterfaceInterceptors();//<2F><>ʾע<CABE><D7A2>ǰ<EFBFBD><C7B0>Ҫִ<D2AA><D6B4>Castle
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

23
CC.Yi.API/T4Startup.cs Normal file
View File

@@ -0,0 +1,23 @@
using Autofac;
using Autofac.Extras.DynamicProxy;
using CC.Yi.BLL;
using CC.Yi.Common.Castle;
using CC.Yi.DAL;
using CC.Yi.IBLL;
using CC.Yi.IDAL;
using System;
namespace CC.Yi.API
{
public partial class Startup
{
//动态 面向AOP思想的依赖注入 Autofac
public void ConfigureContainer(ContainerBuilder builder)
{
builder.RegisterType(typeof(CustomAutofacAop));
builder.RegisterGeneric(typeof(BaseDal<>)).As(typeof(IBaseDal<>));
builder.RegisterType<studentBll>().As<IstudentBll>().EnableInterfaceInterceptors();//表示注入前后要执行CastleAOP
}
}
}

40
CC.Yi.API/T4Startup.tt Normal file
View File

@@ -0,0 +1,40 @@
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.IO" #>
<#@ output extension=".cs" #>
<#
string solutionsPath = Host.ResolveAssemblyReference("$(SolutionDir)");//获取解决方案路径
string txt;
StreamReader sr = new StreamReader(solutionsPath+@"\T4Model\T4Model.txt");
txt=sr.ReadToEnd();
sr.Close();
string[] ModelData= txt.Split(',');
#>
using Autofac;
using Autofac.Extras.DynamicProxy;
using CC.Yi.BLL;
using CC.Yi.Common.Castle;
using CC.Yi.DAL;
using CC.Yi.IBLL;
using CC.Yi.IDAL;
using System;
namespace CC.Yi.API
{
public partial class Startup
{
//动态 面向AOP思想的依赖注入 Autofac
public void ConfigureContainer(ContainerBuilder builder)
{
builder.RegisterType(typeof(CustomAutofacAop));
builder.RegisterGeneric(typeof(BaseDal<>)).As(typeof(IBaseDal<>));
<# foreach(string k in ModelData){#>
builder.RegisterType<<#=k #>Bll>().As<I<#=k #>Bll>().EnableInterfaceInterceptors();//表示注入前后要执行CastleAOP
<# } #>
}
}
}

5
T4Model/说明.txt Normal file
View File

@@ -0,0 +1,5 @@
这里存放T4要生成的模型
使用英文的 , 分隔
例如:
student,teacher
点击 生成->转换所有t4模板 即可完成生成

16
test.cs Normal file
View File

@@ -0,0 +1,16 @@
using System;
namespace CC.Yi.API
{
public class Startup
{
//动态 面向AOP思想的依赖注入 Autofac
public void ConfigureContainer(ContainerBuilder builder)
{
builder.RegisterType(typeof(CustomAutofacAop));
builder.RegisterGeneric(typeof(BaseDal<>)).As(typeof(IBaseDal<>));
builder.RegisterType<studentBll>().As<IstudentBll>().EnableInterfaceInterceptors();//表示注入前后要执行CastleAOP
}
}
}