Browse Source

调整 HostApp移除自带新版ApiUI功能,通过配置中间件方法自行引用

zhontai 2 years ago
parent
commit
ad5d5609ac

+ 31 - 2
src/hosts/ZhonTai.Host/Program.cs

@@ -1,6 +1,35 @@
-using ZhonTai.Admin.Core;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using System.Linq;
+using ZhonTai.Admin.Core;
+using ZhonTai.Admin.Core.Configs;
+using ZhonTai.Admin.Core.Enums;
+using ZhonTai.Admin.Core.Startup;
+using ZhonTai.ApiUI;
 
-new HostApp().Run(args);
+new HostApp(new HostAppOptions
+{
+    ConfigurePostMiddleware = context =>
+    {
+		var app = context.App;
+		var env = app.Environment;
+		var appConfig = app.Services.GetService<AppConfig>();
+
+		#region 新版Api文档
+		if (env.IsDevelopment() || appConfig.ApiUI.Enable)
+		{
+			app.UseApiUI(options =>
+			{
+				options.RoutePrefix = "swagger";
+				typeof(ApiVersion).GetEnumNames().OrderByDescending(e => e).ToList().ForEach(version =>
+				{
+					options.SwaggerEndpoint($"/swagger/{version}/swagger.json", $"ZhonTai.Host {version}");
+				});
+			});
+		}
+		#endregion
+	}
+}).Run(args);
 
 #if DEBUG
 public partial class Program { }

+ 1 - 0
src/hosts/ZhonTai.Host/ZhonTai.Host.csproj

@@ -11,6 +11,7 @@
 
 	<ItemGroup>
 		<ProjectReference Include="..\..\platform\ZhonTai.Admin\ZhonTai.Admin.csproj" />
+		<ProjectReference Include="..\..\platform\ZhonTai.ApiUI\ZhonTai.ApiUI.csproj" />
 	</ItemGroup>
 
 	<ItemGroup>

+ 0 - 15
src/platform/ZhonTai.Admin/Core/HostApp.cs

@@ -42,7 +42,6 @@ using ZhonTai.Admin.Core.Configs;
 using ZhonTai.Admin.Core.Consts;
 using MapsterMapper;
 using ZhonTai.DynamicApi;
-using ZhonTai.ApiUI;
 using NLog.Web;
 using Autofac.Extensions.DependencyInjection;
 using Microsoft.AspNetCore.Mvc;
@@ -590,20 +589,6 @@ namespace ZhonTai.Admin.Core
             }
             #endregion Swagger Api文档
 
-            #region 新版Api文档
-            if (env.IsDevelopment() || appConfig.ApiUI.Enable)
-            {
-                app.UseApiUI(options =>
-                {
-                    options.RoutePrefix = "swagger";
-                    typeof(ApiVersion).GetEnumNames().OrderByDescending(e => e).ToList().ForEach(version =>
-                    {
-                        options.SwaggerEndpoint($"/swagger/{version}/swagger.json", $"ZhonTai.Host {version}");
-                    });
-                });
-            }
-            #endregion
-
             //数据库日志
             //var log = LogManager.GetLogger("db");
             //var ei = new LogEventInfo(LogLevel.Error, "", "错误信息");

+ 8 - 6
src/platform/ZhonTai.Admin/ZhonTai.Admin.csproj

@@ -17,11 +17,6 @@
 		<PackageReference Include="Caching.CSRedis" Version="3.8.3" />
 		<PackageReference Include="FluentValidation.AspNetCore" Version="11.1.2" />
 		<PackageReference Include="FreeSql" Version="3.2.665" />
-		<PackageReference Include="FreeSql.Provider.MySql" Version="3.2.665" />
-		<PackageReference Include="FreeSql.Provider.Oracle" Version="3.2.665" />
-		<PackageReference Include="FreeSql.Provider.PostgreSQL" Version="3.2.665" />
-		<PackageReference Include="FreeSql.Provider.Sqlite" Version="3.2.665" />
-		<PackageReference Include="FreeSql.Provider.SqlServer" Version="3.2.665" />
 		<PackageReference Include="FreeSql.Repository" Version="3.2.665" />
 		<PackageReference Include="IdleBus" Version="1.5.2" />
 		<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
@@ -40,8 +35,15 @@
 		<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
 	</ItemGroup>
 
+	<ItemGroup Condition="'$(Configuration)'=='Debug'">
+		<PackageReference Include="FreeSql.Provider.MySql" Version="3.2.665" />
+		<PackageReference Include="FreeSql.Provider.SqlServer" Version="3.2.665" />
+		<PackageReference Include="FreeSql.Provider.PostgreSQL" Version="3.2.665" />
+		<PackageReference Include="FreeSql.Provider.Oracle" Version="3.2.665" />
+		<PackageReference Include="FreeSql.Provider.Sqlite" Version="3.2.665" />
+	</ItemGroup>
+
 	<ItemGroup>
-		<ProjectReference Include="..\ZhonTai.ApiUI\ZhonTai.ApiUI.csproj" />
 		<ProjectReference Include="..\ZhonTai.Common\ZhonTai.Common.csproj" />
 		<ProjectReference Include="..\ZhonTai.DynamicApi\ZhonTai.DynamicApi.csproj" />
 	</ItemGroup>