diff --git a/ds-wms-service/DS.Module.Core/DS.Module.Core.csproj b/ds-wms-service/DS.Module.Core/DS.Module.Core.csproj index f2b01030..62d712de 100644 --- a/ds-wms-service/DS.Module.Core/DS.Module.Core.csproj +++ b/ds-wms-service/DS.Module.Core/DS.Module.Core.csproj @@ -23,6 +23,8 @@ + + diff --git a/ds-wms-service/DS.Module.Core/Middlewares/UseCommonMiddlewares.cs b/ds-wms-service/DS.Module.Core/Middlewares/UseCommonMiddlewares.cs index e3933b8d..09d6fe27 100644 --- a/ds-wms-service/DS.Module.Core/Middlewares/UseCommonMiddlewares.cs +++ b/ds-wms-service/DS.Module.Core/Middlewares/UseCommonMiddlewares.cs @@ -1,5 +1,6 @@ using DS.Module.Core.Extensions; using Microsoft.AspNetCore.Builder; +using Swashbuckle.AspNetCore.SwaggerUI; namespace DS.Module.Core.Middlewares { @@ -16,15 +17,15 @@ namespace DS.Module.Core.Middlewares public static WebApplication UsePublicMiddlewares(this WebApplication app) { var documentName = AppSetting.app(new string[] { "SwaggerDoc", "ContactName" }); - //app - // .UseSwagger(c => { c.RouteTemplate = "{documentName}/swagger.json"; }) - // .UseSwaggerUI(c => - // { - // c.SwaggerEndpoint("/" + documentName + "/swagger.json", - // AppSetting.app(new string[] { "SwaggerDoc", "ContactName" })); - // c.DocExpansion(DocExpansion.None);//DocExpansion设置为None可折叠所有方法 - // c.DefaultModelExpandDepth(-1);//-1 可不显示Models - // }); + app + .UseSwagger(c => { c.RouteTemplate = "{documentName}/swagger.json"; }) + .UseSwaggerUI(c => + { + c.SwaggerEndpoint("/" + documentName + "/swagger.json", + AppSetting.app(new string[] { "SwaggerDoc", "ContactName" })); + c.DocExpansion(DocExpansion.None);//DocExpansion设置为None可折叠所有方法 + c.DefaultModelExpandDepth(-1);//-1 可不显示Models + }); //跨域 var policyName = AppSetting.app(new string[] { "Cors", "PolicyName" }); if (!policyName.IsNullOrEmpty()) diff --git a/ds-wms-service/DS.Module.Middleware/DS.Module.Middleware.csproj b/ds-wms-service/DS.Module.Middleware/DS.Module.Middleware.csproj index 2e8817d2..ed3a87c7 100644 --- a/ds-wms-service/DS.Module.Middleware/DS.Module.Middleware.csproj +++ b/ds-wms-service/DS.Module.Middleware/DS.Module.Middleware.csproj @@ -9,7 +9,10 @@ + + + diff --git a/ds-wms-service/DS.Module.Middleware/PublicServiceExtensions.cs b/ds-wms-service/DS.Module.Middleware/PublicServiceExtensions.cs new file mode 100644 index 00000000..897821ca --- /dev/null +++ b/ds-wms-service/DS.Module.Middleware/PublicServiceExtensions.cs @@ -0,0 +1,54 @@ +using Autofac; +using Autofac.Extensions.DependencyInjection; +using DS.Module.Core.Extensions; +using DS.Module.MultiLanguage; +using DS.Module.SqlSugar; +using DS.Module.Swagger; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Configuration; +using NLog.Web; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.Module.Middleware.ServiceExtensions +{ + public static class PublicServiceExtensions + { + + public static WebApplicationBuilder AddPublicService(this WebApplicationBuilder builder) + { + var environment = builder.Environment.EnvironmentName; + Console.WriteLine("当前开发环境:" + environment); + //注册配置 + builder.Configuration + // .SetBasePath(builder.Environment.ContentRootPath) + .AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true) + // .AddJsonFile(path: $"appsettings.{environment}.json", optional: true, reloadOnChange: true) + .Build(); + builder.Configuration.AddEnvironmentVariables(); + builder.Logging.AddNLog("nlog.config"); + // Add services to the container. + ////Autofac注入 + //builder.Host + // .UseServiceProviderFactory(new AutofacServiceProviderFactory()) + // .ConfigureContainer(builder => { builder.RegisterModule(new AutofacModuleRegister()); }); + + //builder.Services.AddAppWebInstal(); + //builder.Services.AddCorsInstall(); + //builder.Services.AddUserModuleInstall(); //用户服务 + //builder.Services.AddSqlSugarInstall(); + //builder.Services.AddSwaggerInstall(); + //builder.Services.AddJwtInstall(); + builder.Services.AddSaasDbInstall();//分库服务 + builder.Services.AddMultiLanguageInstall();//多语言服务 + // builder.Services.AddEndpointsApiExplorer(); + // builder.Services.AddSwaggerGen(); + + return builder; + } + + } +} diff --git a/ds-wms-service/DS.WMS.FeeApi/Program.cs b/ds-wms-service/DS.WMS.FeeApi/Program.cs index 59b58a9c..3d80f95a 100644 --- a/ds-wms-service/DS.WMS.FeeApi/Program.cs +++ b/ds-wms-service/DS.WMS.FeeApi/Program.cs @@ -3,6 +3,7 @@ using Autofac.Extensions.DependencyInjection; using DS.Module.AutofacModule; using DS.Module.Core; using DS.Module.Core.Extensions; +using DS.Module.Core.Middlewares; using DS.Module.Core.ServiceExtensions; using DS.Module.ExcelModule; using DS.Module.Jwt; @@ -43,43 +44,36 @@ builder.Services.AddMultiLanguageInstall();// var app = builder.Build(); -// Configure the HTTP request pipeline. -// if (app.Environment.IsDevelopment()) -// { -// app.UseSwagger(); -// app.UseSwaggerUI(); -// } -//swagger -// app.UseSwagger(); -var documentName = AppSetting.app(new string[] { "SwaggerDoc", "ContactName" }); -app - .UseSwagger(c => { c.RouteTemplate = "{documentName}/swagger.json"; }) - .UseSwaggerUI(c => - { - c.SwaggerEndpoint("/" + documentName + "/swagger.json", - AppSetting.app(new string[] { "SwaggerDoc", "ContactName" })); - c.DocExpansion(DocExpansion.None);//DocExpansionΪNone۵з - c.DefaultModelExpandDepth(-1);//-1 ɲʾModels - }); -// -var policyName = AppSetting.app(new string[] { "Cors", "PolicyName" }); -if (!policyName.IsNullOrEmpty()) -{ - app.UseCors(policyName); //ӿм -} +app.UsePublicMiddlewares(); +//var documentName = AppSetting.app(new string[] { "SwaggerDoc", "ContactName" }); +//app +// .UseSwagger(c => { c.RouteTemplate = "{documentName}/swagger.json"; }) +// .UseSwaggerUI(c => +// { +// c.SwaggerEndpoint("/" + documentName + "/swagger.json", +// AppSetting.app(new string[] { "SwaggerDoc", "ContactName" })); +// c.DocExpansion(DocExpansion.None);//DocExpansionΪNone۵з +// c.DefaultModelExpandDepth(-1);//-1 ɲʾModels +// }); +//// +//var policyName = AppSetting.app(new string[] { "Cors", "PolicyName" }); +//if (!policyName.IsNullOrEmpty()) +//{ +// app.UseCors(policyName); //ӿм +//} -app.UseRouting(); +//app.UseRouting(); -app.UseStaticFiles(); -//м -app.UseMiddleware(); -// //־м -// app.UseMiddleware(); +//app.UseStaticFiles(); +////м +//app.UseMiddleware(); +//// //־м +//// app.UseMiddleware(); -// ȿ֤ -app.UseAuthentication(); -// ȻȨм -app.UseAuthorization(); -app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); +//// ȿ֤ +//app.UseAuthentication(); +//// ȻȨм +//app.UseAuthorization(); +//app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.Run(); \ No newline at end of file