From 10a6cc8dc7e8b0c2d6999b2a28789eb91a4112dd Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 6 Dec 2023 10:31:02 +0800 Subject: [PATCH] Use `Asp.Versioning.Mvc` to replace `Microsoft.AspNetCore.Mvc.Versioning`. Resolve #18368 --- Directory.Packages.props | 2 +- .../AbpApiVersioningExtensions.cs | 22 +++++++++++-------- .../Volo.Abp.AspNetCore.Mvc.csproj | 2 +- .../AspNetCoreApiDescriptionModelProvider.cs | 5 +---- ...pConventionalApiControllerSpecification.cs | 1 + .../ConventionalControllerSetting.cs | 13 +++++------ .../AbpAspNetCoreMvcVersioningTestModule.cs | 6 +++-- .../Mvc/Versioning/App/HelloController.cs | 2 ++ .../Abp/Account/DynamicClaimsController.cs | 1 + .../Volo/Abp/Account/ProfileController.cs | 1 + .../Account/Controllers/AccountController.cs | 1 + .../Docs/Admin/DocumentsAdminController.cs | 1 + .../Docs/Admin/ProjectsAdminController.cs | 1 + .../Docs/Documents/DocsDocumentController.cs | 1 + .../Docs/Projects/DocsProjectController.cs | 1 + .../Documents/DocumentResourceController.cs | 1 + .../Abp/Identity/IdentityRoleController.cs | 1 + .../Abp/Identity/IdentityUserController.cs | 1 + .../Identity/IdentityUserLookupController.cs | 1 + .../IdentityUserIntegrationController.cs | 1 + .../PermissionIntegrationController.cs | 1 + 21 files changed, 42 insertions(+), 24 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 540c7f109d..4bcf74bef2 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -11,6 +11,7 @@ + @@ -60,7 +61,6 @@ - diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpApiVersioningExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpApiVersioningExtensions.cs index 6521e7fd43..c3f93fc06c 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpApiVersioningExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpApiVersioningExtensions.cs @@ -1,8 +1,7 @@ using System; using System.Linq; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.ApplicationModels; -using Microsoft.AspNetCore.Mvc.Versioning; +using Asp.Versioning; +using Asp.Versioning.ApplicationModels; using Volo.Abp.ApiVersioning; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.Conventions; @@ -12,32 +11,37 @@ namespace Microsoft.Extensions.DependencyInjection; public static class AbpApiVersioningExtensions { - public static IServiceCollection AddAbpApiVersioning(this IServiceCollection services, Action setupAction) + public static IServiceCollection AddAbpApiVersioning( + this IServiceCollection services, + Action? apiVersioningOptionsSetupAction = null, + Action? mvcApiVersioningOptionsSetupAction = null) { services.AddTransient(); services.AddTransient(); - services.AddApiVersioning(setupAction); + apiVersioningOptionsSetupAction ??= _ => { }; + mvcApiVersioningOptionsSetupAction ??= _ => { }; + services.AddApiVersioning(apiVersioningOptionsSetupAction).AddMvc(mvcApiVersioningOptionsSetupAction); return services; } - public static void ConfigureAbp(this ApiVersioningOptions options, AbpAspNetCoreMvcOptions mvcOptions) + public static void ConfigureAbp(this MvcApiVersioningOptions options, AbpAspNetCoreMvcOptions mvcOptions) { foreach (var setting in mvcOptions.ConventionalControllers.ConventionalControllerSettings) { - if (setting.ApiVersionConfigurer == null) + if (setting.MvcApiVersioningConfigurer == null) { ConfigureApiVersionsByConvention(options, setting); } else { - setting.ApiVersionConfigurer.Invoke(options); + setting.MvcApiVersioningConfigurer.Invoke(options); } } } - private static void ConfigureApiVersionsByConvention(ApiVersioningOptions options, ConventionalControllerSetting setting) + private static void ConfigureApiVersionsByConvention(MvcApiVersioningOptions options, ConventionalControllerSetting setting) { foreach (var controllerType in setting.ControllerTypes) { diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo.Abp.AspNetCore.Mvc.csproj b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo.Abp.AspNetCore.Mvc.csproj index 14c7111a5c..c52ec08b2a 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo.Abp.AspNetCore.Mvc.csproj +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo.Abp.AspNetCore.Mvc.csproj @@ -31,7 +31,7 @@ - + diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs index 681dc14d8f..ad3dcc003e 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs @@ -2,19 +2,16 @@ using System; using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Text; +using Asp.Versioning; using JetBrains.Annotations; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.ApiExplorer; -using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.AspNetCore.Mvc.Versioning; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; -using Volo.Abp.Application.Services; using Volo.Abp.AspNetCore.Mvc.Conventions; using Volo.Abp.AspNetCore.Mvc.Utils; using Volo.Abp.DependencyInjection; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpConventionalApiControllerSpecification.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpConventionalApiControllerSpecification.cs index 325bc854ce..01414e2856 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpConventionalApiControllerSpecification.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpConventionalApiControllerSpecification.cs @@ -1,3 +1,4 @@ +using Asp.Versioning.ApplicationModels; using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.Extensions.Options; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSetting.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSetting.cs index 5523a52020..7168cecd1e 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSetting.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSetting.cs @@ -1,12 +1,11 @@ using JetBrains.Annotations; -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ApplicationModels; -using Microsoft.AspNetCore.Mvc.Versioning; using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using System.Reflection; +using Asp.Versioning; using Volo.Abp.Reflection; namespace Volo.Abp.AspNetCore.Mvc.Conventions; @@ -60,7 +59,7 @@ public class ConventionalControllerSetting public List ApiVersions { get; } - public Action? ApiVersionConfigurer { get; set; } + public Action? MvcApiVersioningConfigurer { get; set; } public ConventionalControllerSetting( [NotNull] Assembly assembly, @@ -87,7 +86,7 @@ public class ConventionalControllerSetting ControllerTypes.Add(type); } } - + public IReadOnlyList GetControllerTypes() { return ControllerTypes.ToImmutableList(); @@ -113,14 +112,14 @@ public class ConventionalControllerSetting return false; } - + private bool IsPreferredApplicationServiceType(Type type) { if (ApplicationServiceTypes == ApplicationServiceTypes.ApplicationServices) { return !IntegrationServiceAttribute.IsDefinedOrInherited(type); } - + if (ApplicationServiceTypes == ApplicationServiceTypes.IntegrationServices) { return IntegrationServiceAttribute.IsDefinedOrInherited(type); @@ -128,4 +127,4 @@ public class ConventionalControllerSetting return true; } -} \ No newline at end of file +} diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AbpAspNetCoreMvcVersioningTestModule.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AbpAspNetCoreMvcVersioningTestModule.cs index a8d2a4ff70..af633539bb 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AbpAspNetCoreMvcVersioningTestModule.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AbpAspNetCoreMvcVersioningTestModule.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Builder; +using Asp.Versioning; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.AspNetCore.TestBase; @@ -51,7 +52,8 @@ public class AbpAspNetCoreMvcVersioningTestModule : AbpModule //options.ApiVersionReader = new HeaderApiVersionReader("api-version"); //Supports header too //options.ApiVersionReader = new MediaTypeApiVersionReader(); //Supports accept header too - + }, options => + { options.ConfigureAbp(preActions.Configure()); }); diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/HelloController.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/HelloController.cs index 4c6b62d649..14defbb0e0 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/HelloController.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/App/HelloController.cs @@ -1,4 +1,6 @@ using System.Threading.Tasks; +using Asp.Versioning; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace Volo.Abp.AspNetCore.Mvc.Versioning.App; diff --git a/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/DynamicClaimsController.cs b/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/DynamicClaimsController.cs index f3546e6607..086f524d39 100644 --- a/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/DynamicClaimsController.cs +++ b/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/DynamicClaimsController.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Threading.Tasks; +using Asp.Versioning; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc; diff --git a/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/ProfileController.cs b/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/ProfileController.cs index 626348f383..6af9ce56d2 100644 --- a/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/ProfileController.cs +++ b/modules/account/src/Volo.Abp.Account.HttpApi/Volo/Abp/Account/ProfileController.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using Asp.Versioning; using Microsoft.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc; diff --git a/modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs b/modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs index 9caff2c187..fbac7129c2 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Areas/Account/Controllers/AccountController.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using Asp.Versioning; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; diff --git a/modules/docs/src/Volo.Docs.Admin.HttpApi/Volo/Docs/Admin/DocumentsAdminController.cs b/modules/docs/src/Volo.Docs.Admin.HttpApi/Volo/Docs/Admin/DocumentsAdminController.cs index bbb12f34db..eb78095bf2 100644 --- a/modules/docs/src/Volo.Docs.Admin.HttpApi/Volo/Docs/Admin/DocumentsAdminController.cs +++ b/modules/docs/src/Volo.Docs.Admin.HttpApi/Volo/Docs/Admin/DocumentsAdminController.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Asp.Versioning; using Microsoft.AspNetCore.Mvc; using Volo.Abp; using Volo.Abp.Application.Dtos; diff --git a/modules/docs/src/Volo.Docs.Admin.HttpApi/Volo/Docs/Admin/ProjectsAdminController.cs b/modules/docs/src/Volo.Docs.Admin.HttpApi/Volo/Docs/Admin/ProjectsAdminController.cs index ea0c7f1afd..5b1cffeae1 100644 --- a/modules/docs/src/Volo.Docs.Admin.HttpApi/Volo/Docs/Admin/ProjectsAdminController.cs +++ b/modules/docs/src/Volo.Docs.Admin.HttpApi/Volo/Docs/Admin/ProjectsAdminController.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Asp.Versioning; using Microsoft.AspNetCore.Mvc; using Volo.Abp; using Volo.Abp.Application.Dtos; diff --git a/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs b/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs index 2fd22c34a8..45a5cdf515 100644 --- a/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs +++ b/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Asp.Versioning; using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.Abp.AspNetCore.Mvc; diff --git a/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Projects/DocsProjectController.cs b/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Projects/DocsProjectController.cs index 4e75eed45f..1cc1f80cc8 100644 --- a/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Projects/DocsProjectController.cs +++ b/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Projects/DocsProjectController.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Asp.Versioning; using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.Abp.AspNetCore.Mvc; diff --git a/modules/docs/src/Volo.Docs.Web/Areas/Documents/DocumentResourceController.cs b/modules/docs/src/Volo.Docs.Web/Areas/Documents/DocumentResourceController.cs index 7b2099a27c..3e21bab9c7 100644 --- a/modules/docs/src/Volo.Docs.Web/Areas/Documents/DocumentResourceController.cs +++ b/modules/docs/src/Volo.Docs.Web/Areas/Documents/DocumentResourceController.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Asp.Versioning; using Volo.Abp; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.Http; diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityRoleController.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityRoleController.cs index 41d2f341f0..8567efe242 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityRoleController.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityRoleController.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using Asp.Versioning; using Microsoft.AspNetCore.Mvc; using Volo.Abp.Application.Dtos; using Volo.Abp.AspNetCore.Mvc; diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs index 4381636a7b..67039a1800 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserController.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using Asp.Versioning; using Microsoft.AspNetCore.Mvc; using Volo.Abp.Application.Dtos; using Volo.Abp.AspNetCore.Mvc; diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs index 4db70514bd..e8fb035c42 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/IdentityUserLookupController.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using Asp.Versioning; using Microsoft.AspNetCore.Mvc; using Volo.Abp.Application.Dtos; using Volo.Abp.AspNetCore.Mvc; diff --git a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/Integration/IdentityUserIntegrationController.cs b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/Integration/IdentityUserIntegrationController.cs index e78691b1ac..2a84385e48 100644 --- a/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/Integration/IdentityUserIntegrationController.cs +++ b/modules/identity/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/Integration/IdentityUserIntegrationController.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using Asp.Versioning; using Microsoft.AspNetCore.Mvc; using Volo.Abp.Application.Dtos; using Volo.Abp.AspNetCore.Mvc; diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.HttpApi/Volo/Abp/PermissionManagement/Integration/PermissionIntegrationController.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.HttpApi/Volo/Abp/PermissionManagement/Integration/PermissionIntegrationController.cs index 48ba4b9541..8a25abfd4b 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.HttpApi/Volo/Abp/PermissionManagement/Integration/PermissionIntegrationController.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.HttpApi/Volo/Abp/PermissionManagement/Integration/PermissionIntegrationController.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Threading.Tasks; +using Asp.Versioning; using Microsoft.AspNetCore.Mvc; using Volo.Abp.Application.Dtos; using Volo.Abp.AspNetCore.Mvc;