From 1bd035e1cab64370b4f969057f7ffd8453391ae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Sat, 14 Jan 2023 18:46:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E7=9B=AE=E5=BD=95=E7=BB=93?= =?UTF-8?q?=E6=9E=84=EF=BC=8C=E5=88=86=E5=B1=82=E5=9F=BA=E6=9C=AC=E5=B7=B2?= =?UTF-8?q?=E7=BB=8F=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit c905489ea5a45511ddd1d0d37975ae66419053e1. --- .../Student/StudentService.cs | 11 ++++--- .../Yi.Framework.Application/SwaggerDoc.xml | 7 ++++ .../Yi.Framework.Application.csproj | 1 + .../SwaggerAddExtensions.cs | 16 ++++++---- .../Yi.Framework.AspNetCore.csproj | 1 + .../Extensions/AutoMapperExtensions.cs | 2 +- .../Yi.Framework.Core.AutoMapper.csproj | 4 +++ .../Helper/AssemblyHelper.cs | 7 ++-- .../Yi.Framework.Core.csproj | 2 -- src/Yi.Framework/Yi.Framework.Web/Program.cs | 30 +++-------------- .../Yi.Framework.Web/Yi.Framework.Web.csproj | 1 - .../Yi.Framework.Web/YiFrameworkWebModule.cs | 32 ++++++++++++++++--- 12 files changed, 66 insertions(+), 48 deletions(-) diff --git a/src/Yi.Framework/Yi.Framework.Application/Student/StudentService.cs b/src/Yi.Framework/Yi.Framework.Application/Student/StudentService.cs index 2e896389..96c949af 100644 --- a/src/Yi.Framework/Yi.Framework.Application/Student/StudentService.cs +++ b/src/Yi.Framework/Yi.Framework.Application/Student/StudentService.cs @@ -24,11 +24,14 @@ namespace Yi.Framework.Application.Student _studentRepository = studentRepository; _studentManager = studentManager; } - - public string PostShijie(IFormFile formFile) + /// + /// 你好世界 + /// + /// + /// + public string PostShijie(string aaa) { - var ss = formFile; - return "你好世界"; + return aaa; } } } diff --git a/src/Yi.Framework/Yi.Framework.Application/SwaggerDoc.xml b/src/Yi.Framework/Yi.Framework.Application/SwaggerDoc.xml index 221447a6..1d37e65a 100644 --- a/src/Yi.Framework/Yi.Framework.Application/SwaggerDoc.xml +++ b/src/Yi.Framework/Yi.Framework.Application/SwaggerDoc.xml @@ -9,5 +9,12 @@ 服务实现 + + + 你好世界 + + + + diff --git a/src/Yi.Framework/Yi.Framework.Application/Yi.Framework.Application.csproj b/src/Yi.Framework/Yi.Framework.Application/Yi.Framework.Application.csproj index 121d981f..b3cbc75f 100644 --- a/src/Yi.Framework/Yi.Framework.Application/Yi.Framework.Application.csproj +++ b/src/Yi.Framework/Yi.Framework.Application/Yi.Framework.Application.csproj @@ -10,6 +10,7 @@ + diff --git a/src/Yi.Framework/Yi.Framework.AspNetCore/Microsoft/Extensions/DependencyInjection/SwaggerAddExtensions.cs b/src/Yi.Framework/Yi.Framework.AspNetCore/Microsoft/Extensions/DependencyInjection/SwaggerAddExtensions.cs index fe322ea5..19e8c804 100644 --- a/src/Yi.Framework/Yi.Framework.AspNetCore/Microsoft/Extensions/DependencyInjection/SwaggerAddExtensions.cs +++ b/src/Yi.Framework/Yi.Framework.AspNetCore/Microsoft/Extensions/DependencyInjection/SwaggerAddExtensions.cs @@ -29,15 +29,19 @@ namespace Microsoft.Extensions.DependencyInjection //添加注释服务 //为 Swagger JSON and UI设置xml文档注释路径 //获取应用程序所在目录(绝对路径,不受工作目录影响,建议采用此方法获取路径使用windwos&Linux) + var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location); - if (basePath is null) + if (basePath is not null) { - throw new Exception("未找到swagger文件"); + foreach (var item in Directory.GetFiles(basePath, "*.xml")) + { + c.IncludeXmlComments(item, true); + } } - var apiXmlPath = Path.Combine(basePath, @"SwaggerDoc.xml");//控制器层注释 - //var entityXmlPath = Path.Combine(basePath, @"SwaggerDoc.xml");//实体注释 - //c.IncludeXmlComments(apiXmlPath, true);//true表示显示控制器注释 - //c.IncludeXmlComments(apiXmlPath, true); + //控制器层注释 + //var entityXmlPath = Path.Combine(basePath, @"SwaggerDoc.xml");//实体注释 + //c.IncludeXmlComments(apiXmlPath, true);//true表示显示控制器注释 + //c.IncludeXmlComments(apiXmlPath, true); //这里路径应该动态获取,先暂时写死 //c.IncludeXmlComments("E:\\Yi\\src\\Yi.Framework\\Yi.Framework.Application\\SwaggerDoc.xml", true); diff --git a/src/Yi.Framework/Yi.Framework.AspNetCore/Yi.Framework.AspNetCore.csproj b/src/Yi.Framework/Yi.Framework.AspNetCore/Yi.Framework.AspNetCore.csproj index 00516e6b..240afa87 100644 --- a/src/Yi.Framework/Yi.Framework.AspNetCore/Yi.Framework.AspNetCore.csproj +++ b/src/Yi.Framework/Yi.Framework.AspNetCore/Yi.Framework.AspNetCore.csproj @@ -9,6 +9,7 @@ + diff --git a/src/Yi.Framework/Yi.Framework.Core.AutoMapper/Extensions/AutoMapperExtensions.cs b/src/Yi.Framework/Yi.Framework.Core.AutoMapper/Extensions/AutoMapperExtensions.cs index da569fc5..153206ad 100644 --- a/src/Yi.Framework/Yi.Framework.Core.AutoMapper/Extensions/AutoMapperExtensions.cs +++ b/src/Yi.Framework/Yi.Framework.Core.AutoMapper/Extensions/AutoMapperExtensions.cs @@ -22,7 +22,7 @@ namespace Yi.Framework.Autofac.Extensions { if (a.FullName is not null) { - profileList.AddRange(AssemblyHelper.GetClassByBaseClassesAndInterfaces(a.FullName, typeof(Profile))); + profileList.AddRange(AssemblyHelper.GetClassByInterfaces(a.FullName, typeof(Profile))); } }); diff --git a/src/Yi.Framework/Yi.Framework.Core.AutoMapper/Yi.Framework.Core.AutoMapper.csproj b/src/Yi.Framework/Yi.Framework.Core.AutoMapper/Yi.Framework.Core.AutoMapper.csproj index e7101d08..a909b82c 100644 --- a/src/Yi.Framework/Yi.Framework.Core.AutoMapper/Yi.Framework.Core.AutoMapper.csproj +++ b/src/Yi.Framework/Yi.Framework.Core.AutoMapper/Yi.Framework.Core.AutoMapper.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/src/Yi.Framework/Yi.Framework.Core/Helper/AssemblyHelper.cs b/src/Yi.Framework/Yi.Framework.Core/Helper/AssemblyHelper.cs index 64491a84..74a320aa 100644 --- a/src/Yi.Framework/Yi.Framework.Core/Helper/AssemblyHelper.cs +++ b/src/Yi.Framework/Yi.Framework.Core/Helper/AssemblyHelper.cs @@ -1,5 +1,4 @@ -using AutoMapper.Internal; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -42,7 +41,7 @@ namespace Yi.Framework.Core.Helper ).ToList(); } - public static List GetClassByBaseClassesAndInterfaces(string assemblyFile, Type type) + public static List GetClassByInterfaces(string assemblyFile, Type type) { Assembly assembly = Assembly.Load(assemblyFile); @@ -51,7 +50,7 @@ namespace Yi.Framework.Core.Helper List typeList = assembly.GetTypes().Where(m => m.IsClass).ToList(); foreach (var t in typeList) { - var data = t.BaseClassesAndInterfaces(); + var data = t.GetInterfaces(); if (data.Contains(type)) { resList.Add(t); diff --git a/src/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj b/src/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj index b7d607f3..fb962413 100644 --- a/src/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj +++ b/src/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj @@ -11,8 +11,6 @@ - - diff --git a/src/Yi.Framework/Yi.Framework.Web/Program.cs b/src/Yi.Framework/Yi.Framework.Web/Program.cs index 0a0554e9..90d166df 100644 --- a/src/Yi.Framework/Yi.Framework.Web/Program.cs +++ b/src/Yi.Framework/Yi.Framework.Web/Program.cs @@ -16,6 +16,7 @@ using Yi.Framework.Domain.Shared; using Yi.Framework.Sqlsugar; using Yi.Framework.Web; +//ִеĵط var builder = WebApplication.CreateBuilder(args); builder.WebHost.UseUrls(builder.Configuration.GetValue("StartUrl")); @@ -31,40 +32,17 @@ builder.UseYiModules( typeof(YiFrameworkDomainSharedModule).Assembly, typeof(YiFrameworkDomainModule).Assembly, typeof(YiFrameworkApplicationContractsModule).Assembly, - typeof(YiFrameworkApplicationModule).Assembly + typeof(YiFrameworkApplicationModule).Assembly, + typeof(YiFrameworkWebModule).Assembly + ); //ʹautofac builder.Host.UseAutoFacServerProviderFactory(); -//ӿ붯̬api -builder.Services.AddControllers(); -builder.Services.AddAutoApiService(opt => -{ - //NETServiceTestڳӽ̬api - opt.CreateConventional(typeof(YiFrameworkApplicationModule).Assembly); -}); - -//swagger -builder.Services.AddSwaggerServer(); - - var app = builder.Build(); -app.Services.GetRequiredService>(); -//if (app.Environment.IsDevelopment()) -{ - app.UseSwaggerServer(); -} - -app.UseHttpsRedirection(); - -app.UseAuthorization(); - -app.UseRouting(); - //ʹö̬api app.UseAutoApiService(); app.MapControllers(); - app.Run(); diff --git a/src/Yi.Framework/Yi.Framework.Web/Yi.Framework.Web.csproj b/src/Yi.Framework/Yi.Framework.Web/Yi.Framework.Web.csproj index db54d323..f9cd981f 100644 --- a/src/Yi.Framework/Yi.Framework.Web/Yi.Framework.Web.csproj +++ b/src/Yi.Framework/Yi.Framework.Web/Yi.Framework.Web.csproj @@ -8,7 +8,6 @@ - diff --git a/src/Yi.Framework/Yi.Framework.Web/YiFrameworkWebModule.cs b/src/Yi.Framework/Yi.Framework.Web/YiFrameworkWebModule.cs index cb0a1a58..fba4306b 100644 --- a/src/Yi.Framework/Yi.Framework.Web/YiFrameworkWebModule.cs +++ b/src/Yi.Framework/Yi.Framework.Web/YiFrameworkWebModule.cs @@ -1,17 +1,41 @@ -using StartupModules; +using AspNetCore.Microsoft.AspNetCore.Builder; +using StartupModules; +using Yi.Framework.Application; namespace Yi.Framework.Web { + /// + /// 这里是最后执行的模块 + /// public class YiFrameworkWebModule : IStartupModule { public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context) { - + //添加控制器与动态api + services.AddControllers(); + services.AddAutoApiService(opt => + { + //NETServiceTest所在程序集添加进动态api配置 + opt.CreateConventional(typeof(YiFrameworkApplicationModule).Assembly, option => option.RootPath = string.Empty); + }); + + //添加swagger + services.AddSwaggerServer(); } public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context) { - Console.WriteLine("还有谁"); - + //if (app.Environment.IsDevelopment()) + { + app.UseSwaggerServer(); + } + + app.UseHttpsRedirection(); + + app.UseAuthorization(); + + app.UseRouting(); + + } } }