From ea8dd04c8ca3fae7e28278a5500413d47b2f6bc3 Mon Sep 17 00:00:00 2001
From: "454313500@qq.com" <454313500@qq.com>
Date: Tue, 23 Mar 2021 14:27:59 +0800
Subject: [PATCH] v1.0.6
---
CC.Yi.API/CC.Yi.API.csproj | 19 ++++++++++++++++++
CC.Yi.API/Program.cs | 2 +-
CC.Yi.API/Startup.cs | 8 +-------
CC.Yi.API/T4Startup.cs | 23 ++++++++++++++++++++++
CC.Yi.API/T4Startup.tt | 40 ++++++++++++++++++++++++++++++++++++++
T4Model/璇存槑.txt | 5 +++++
test.cs | 16 +++++++++++++++
7 files changed, 105 insertions(+), 8 deletions(-)
create mode 100644 CC.Yi.API/T4Startup.cs
create mode 100644 CC.Yi.API/T4Startup.tt
create mode 100644 T4Model/璇存槑.txt
create mode 100644 test.cs
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