diff --git a/CC.Yi.API/CC.Yi.API.csproj b/CC.Yi.API/CC.Yi.API.csproj index 25450b8f..d2836df9 100644 --- a/CC.Yi.API/CC.Yi.API.csproj +++ b/CC.Yi.API/CC.Yi.API.csproj @@ -27,4 +27,23 @@ + + + + + + + True + True + T4Startup.tt + + + + + + TextTemplatingFileGenerator + T4Startup.cs + + + diff --git a/CC.Yi.API/Program.cs b/CC.Yi.API/Program.cs index 83fc65fc..06ecf46f 100644 --- a/CC.Yi.API/Program.cs +++ b/CC.Yi.API/Program.cs @@ -56,7 +56,7 @@ namespace CC.Yi.API { // logging.ClearProviders(); // 这个方法会清空所有控制台的输出 logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); - }).UseNLog(); + }).UseNLog();//开启nlog日志输出 } } diff --git a/CC.Yi.API/Startup.cs b/CC.Yi.API/Startup.cs index 3206fc1c..5eee61b8 100644 --- a/CC.Yi.API/Startup.cs +++ b/CC.Yi.API/Startup.cs @@ -59,13 +59,7 @@ namespace CC.Yi.API })); } - //动态 面向AOP思想的依赖注入 Autofac - public void ConfigureContainer(ContainerBuilder builder) - { - builder.RegisterType(typeof(CustomAutofacAop)); - builder.RegisterGeneric(typeof(BaseDal<>)).As(typeof(IBaseDal<>)) ; - builder.RegisterType().As().EnableInterfaceInterceptors();//表示注入前后要执行Castle - } + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) diff --git a/CC.Yi.API/T4Startup.cs b/CC.Yi.API/T4Startup.cs new file mode 100644 index 00000000..75e8a6fd --- /dev/null +++ b/CC.Yi.API/T4Startup.cs @@ -0,0 +1,23 @@ +锘縰sing 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().As().EnableInterfaceInterceptors();//琛ㄧず娉ㄥ叆鍓嶅悗瑕佹墽琛孋astle锛孉OP + } + } +} \ No newline at end of file diff --git a/CC.Yi.API/T4Startup.tt b/CC.Yi.API/T4Startup.tt new file mode 100644 index 00000000..166ebfc5 --- /dev/null +++ b/CC.Yi.API/T4Startup.tt @@ -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)");//鑾峰彇瑙e喅鏂规璺緞 + 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>().AsBll>().EnableInterfaceInterceptors();//琛ㄧず娉ㄥ叆鍓嶅悗瑕佹墽琛孋astle锛孉OP +<# } #> + } + } +} \ No newline at end of file diff --git a/T4Model/璇存槑.txt b/T4Model/璇存槑.txt new file mode 100644 index 00000000..7abbdd18 --- /dev/null +++ b/T4Model/璇存槑.txt @@ -0,0 +1,5 @@ +杩欓噷瀛樻斁T4瑕佺敓鎴愮殑妯″瀷 +浣跨敤鑻辨枃鐨 , 鍒嗛殧 +渚嬪锛 +student,teacher +鐐瑰嚮 鐢熸垚->杞崲鎵鏈塼4妯℃澘 鍗冲彲瀹屾垚鐢熸垚 \ No newline at end of file diff --git a/test.cs b/test.cs new file mode 100644 index 00000000..72b12401 --- /dev/null +++ b/test.cs @@ -0,0 +1,16 @@ +锘縰sing 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().As().EnableInterfaceInterceptors();//琛ㄧず娉ㄥ叆鍓嶅悗瑕佹墽琛孋astle锛孉OP + } + } +} \ No newline at end of file