From 29a7cfe9b2330212f412ed0b0e8805cda36879e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 5 Oct 2017 19:09:39 +0300 Subject: [PATCH] Refactored. --- .../AbpDesk.Web.Mvc/AbpDeskWebMvcModule.cs | 2 +- .../AbpApiVersioningOptionsExtensions.cs | 5 +-- .../AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs | 9 ++--- .../AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs | 9 ++--- .../AspNetCore/Mvc/AbpMvcOptionsExtensions.cs | 3 +- .../Mvc/AppServiceControllerOptions.cs | 35 ------------------- .../AspNetCoreApiDescriptionModelProvider.cs | 9 ++--- ...pConventionalControllerFeatureProvider.cs} | 10 +++--- .../AbpServiceConvention.cs} | 35 +++++++++---------- .../AbpServiceConventionWrapper.cs} | 10 +++--- .../ConventionalControllerOptions.cs | 35 +++++++++++++++++++ .../ConventionalControllerSetting.cs} | 6 ++-- .../ConventionalControllerSettingList.cs} | 6 ++-- .../Mvc/Conventions/IAbpServiceConvention.cs | 8 +++++ .../UrlActionNameNormalizerContext.cs | 2 +- .../UrlControllerNameNormalizerContext.cs | 2 +- .../Mvc/IAbpAppServiceConvention.cs | 8 ----- .../AbpIdentityHttpApiHostModule.cs | 5 ++- .../SwaggerDefaultValues.cs | 10 +++--- .../Abp/Identity/AbpIdentityHttpApiModule.cs | 4 +-- .../Mvc/AbpAspNetCoreMvcTestModule.cs | 2 +- .../AbpAspNetCoreMvcVersioningTestModule.cs | 4 +-- 22 files changed, 111 insertions(+), 108 deletions(-) delete mode 100644 src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AppServiceControllerOptions.cs rename src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/{AbpAppServiceControllerFeatureProvider.cs => Conventions/AbpConventionalControllerFeatureProvider.cs} (68%) rename src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/{AbpAppServiceConvention.cs => Conventions/AbpServiceConvention.cs} (88%) rename src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/{AbpAppServiceConventionWrapper.cs => Conventions/AbpServiceConventionWrapper.cs} (50%) create mode 100644 src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerOptions.cs rename src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/{AbpControllerAssemblySetting.cs => Conventions/ConventionalControllerSetting.cs} (92%) rename src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/{ControllerAssemblySettingList.cs => Conventions/ConventionalControllerSettingList.cs} (55%) create mode 100644 src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/IAbpServiceConvention.cs rename src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/{ => Conventions}/UrlActionNameNormalizerContext.cs (93%) rename src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/{ => Conventions}/UrlControllerNameNormalizerContext.cs (87%) delete mode 100644 src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/IAbpAppServiceConvention.cs diff --git a/src/AbpDesk/AbpDesk.Web.Mvc/AbpDeskWebMvcModule.cs b/src/AbpDesk/AbpDesk.Web.Mvc/AbpDeskWebMvcModule.cs index 24addb659f..50c18af252 100644 --- a/src/AbpDesk/AbpDesk.Web.Mvc/AbpDeskWebMvcModule.cs +++ b/src/AbpDesk/AbpDesk.Web.Mvc/AbpDeskWebMvcModule.cs @@ -65,7 +65,7 @@ namespace AbpDesk.Web.Mvc services.Configure(options => { - options.AppServiceControllers.Create(typeof(AbpDeskApplicationModule).Assembly); + options.ConventionalControllers.Create(typeof(AbpDeskApplicationModule).Assembly); }); } diff --git a/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpApiVersioningOptionsExtensions.cs b/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpApiVersioningOptionsExtensions.cs index 7137d7fe3d..c792b563d1 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpApiVersioningOptionsExtensions.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Microsoft/Extensions/DependencyInjection/AbpApiVersioningOptionsExtensions.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc.Versioning; using Microsoft.AspNetCore.Mvc.Versioning.Conventions; using Volo.Abp.ApiVersioning; using Volo.Abp.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc.Conventions; using Volo.Abp.AspNetCore.Mvc.Versioning; namespace Microsoft.Extensions.DependencyInjection @@ -22,7 +23,7 @@ namespace Microsoft.Extensions.DependencyInjection //TODO: Configuring api version should be done directly inside ConfigureAbp, //TODO: not in a callback that will be called by MVC later! For that, we immediately need to controllerAssemblySettings - foreach (var setting in op.AppServiceControllers.ControllerAssemblySettings) + foreach (var setting in op.ConventionalControllers.ConventionalControllerSettings) { if (setting.ApiVersionConfigurer == null) { @@ -36,7 +37,7 @@ namespace Microsoft.Extensions.DependencyInjection }); } - private static void ConfigureApiVersionsByConvention(ApiVersioningOptions options, AbpControllerAssemblySetting setting) + private static void ConfigureApiVersionsByConvention(ApiVersioningOptions options, ConventionalControllerSetting setting) { foreach (var controllerType in setting.ControllerTypes) { diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs index 088936b69d..b06cefdcd1 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs @@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.ViewComponents; using Microsoft.Extensions.DependencyInjection.Extensions; +using Volo.Abp.AspNetCore.Mvc.Conventions; using Volo.Abp.Http; using Volo.Abp.Http.Modeling; @@ -53,7 +54,7 @@ namespace Volo.Abp.AspNetCore.Mvc services.Configure(options => { - options.AppServiceControllers.Create(typeof(AbpAspNetCoreMvcModule).Assembly, o => + options.ConventionalControllers.Create(typeof(AbpAspNetCoreMvcModule).Assembly, o => { o.RootPath = "abp"; }); @@ -77,7 +78,7 @@ namespace Volo.Abp.AspNetCore.Mvc var partManager = services.GetSingletonInstance(); var application = services.GetSingletonInstance(); - partManager.FeatureProviders.Add(new AbpAppServiceControllerFeatureProvider(application)); + partManager.FeatureProviders.Add(new AbpConventionalControllerFeatureProvider(application)); services.Configure(mvcOptions => { @@ -114,8 +115,8 @@ namespace Volo.Abp.AspNetCore.Mvc .ServiceProvider .GetRequiredService>() .Value - .AppServiceControllers - .ControllerAssemblySettings + .ConventionalControllers + .ConventionalControllerSettings .Select(s => s.Assembly) .Distinct(); diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs index 7d2bb24341..6dec2fde14 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcOptions.cs @@ -1,13 +1,14 @@ -namespace Volo.Abp.AspNetCore.Mvc +using Volo.Abp.AspNetCore.Mvc.Conventions; + +namespace Volo.Abp.AspNetCore.Mvc { public class AbpAspNetCoreMvcOptions { - //TODO: Rename to ConventionalControllers - public AppServiceControllerOptions AppServiceControllers { get; } + public ConventionalControllerOptions ConventionalControllers { get; } public AbpAspNetCoreMvcOptions() { - AppServiceControllers = new AppServiceControllerOptions(); + ConventionalControllers = new ConventionalControllerOptions(); } } } \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcOptionsExtensions.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcOptionsExtensions.cs index e0cb1c2232..b18d155573 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcOptionsExtensions.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpMvcOptionsExtensions.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.AspNetCore.Mvc.Conventions; using Volo.Abp.AspNetCore.Mvc.ExceptionHandling; using Volo.Abp.AspNetCore.Mvc.Uow; using Volo.Abp.AspNetCore.Mvc.Validation; @@ -17,7 +18,7 @@ namespace Volo.Abp.AspNetCore.Mvc private static void AddConventions(MvcOptions options, IServiceCollection services) { - options.Conventions.Add(new AbpAppServiceConventionWrapper(services)); + options.Conventions.Add(new AbpServiceConventionWrapper(services)); } private static void AddFilters(MvcOptions options) diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AppServiceControllerOptions.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AppServiceControllerOptions.cs deleted file mode 100644 index 4c677fb8e0..0000000000 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AppServiceControllerOptions.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using JetBrains.Annotations; -using Microsoft.AspNetCore.Http; -using Volo.Abp.Http.Modeling; - -namespace Volo.Abp.AspNetCore.Mvc -{ - public class AppServiceControllerOptions - { - public ControllerAssemblySettingList ControllerAssemblySettings { get; } - - public List FormBodyBindingIgnoredTypes { get; } - - public AppServiceControllerOptions() - { - ControllerAssemblySettings = new ControllerAssemblySettingList(); - - FormBodyBindingIgnoredTypes = new List - { - typeof(IFormFile) - }; - } - - public AppServiceControllerOptions Create(Assembly assembly, [CanBeNull] Action optionsAction = null) - { - var setting = new AbpControllerAssemblySetting(assembly, ModuleApiDescriptionModel.DefaultRootPath); - optionsAction?.Invoke(setting); - setting.Initialize(); - ControllerAssemblySettings.Add(setting); - return this; - } - } -} \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs index 53359745fd..4ddfa24f45 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs @@ -12,6 +12,7 @@ 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; using Volo.Abp.Http.Modeling; @@ -88,7 +89,7 @@ namespace Volo.Abp.AspNetCore.Mvc AddParameterDescriptionsToModel(actionModel, method, apiDescription); } - private static string CalculateControllerName(Type controllerType, AbpControllerAssemblySetting setting) + private static string CalculateControllerName(Type controllerType, ConventionalControllerSetting setting) { var controllerName = controllerType.Name.RemovePostFix("Controller").RemovePostFix(ApplicationService.CommonPostfixes); @@ -169,7 +170,7 @@ namespace Volo.Abp.AspNetCore.Mvc return modelNameProvider.Name; } - private static string GetRootPath([NotNull] Type controllerType, [CanBeNull] AbpControllerAssemblySetting setting) + private static string GetRootPath([NotNull] Type controllerType, [CanBeNull] ConventionalControllerSetting setting) { if (setting != null) { @@ -186,9 +187,9 @@ namespace Volo.Abp.AspNetCore.Mvc } [CanBeNull] - private AbpControllerAssemblySetting FindSetting(Type controllerType) + private ConventionalControllerSetting FindSetting(Type controllerType) { - foreach (var controllerSetting in _options.AppServiceControllers.ControllerAssemblySettings) + foreach (var controllerSetting in _options.ConventionalControllers.ConventionalControllerSettings) { if (controllerSetting.ControllerTypes.Contains(controllerType)) { diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceControllerFeatureProvider.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpConventionalControllerFeatureProvider.cs similarity index 68% rename from src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceControllerFeatureProvider.cs rename to src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpConventionalControllerFeatureProvider.cs index a9165f1409..e04574a03b 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceControllerFeatureProvider.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpConventionalControllerFeatureProvider.cs @@ -3,13 +3,13 @@ using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; -namespace Volo.Abp.AspNetCore.Mvc +namespace Volo.Abp.AspNetCore.Mvc.Conventions { - public class AbpAppServiceControllerFeatureProvider : ControllerFeatureProvider + public class AbpConventionalControllerFeatureProvider : ControllerFeatureProvider { private readonly IAbpApplication _application; - public AbpAppServiceControllerFeatureProvider(IAbpApplication application) + public AbpConventionalControllerFeatureProvider(IAbpApplication application) { _application = application; } @@ -19,8 +19,8 @@ namespace Volo.Abp.AspNetCore.Mvc //TODO: Move this to a lazy loaded field for efficiency. var configuration = _application.ServiceProvider .GetRequiredService>().Value - .AppServiceControllers - .ControllerAssemblySettings + .ConventionalControllers + .ConventionalControllerSettings .GetSettingOrNull(typeInfo.AsType()); return configuration != null; diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConvention.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpServiceConvention.cs similarity index 88% rename from src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConvention.cs rename to src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpServiceConvention.cs index dd261936e2..946be023cc 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConvention.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpServiceConvention.cs @@ -14,13 +14,13 @@ using Volo.Abp.Http; using Volo.Abp.Http.Modeling; using Volo.Abp.Reflection; -namespace Volo.Abp.AspNetCore.Mvc +namespace Volo.Abp.AspNetCore.Mvc.Conventions { - public class AbpAppServiceConvention : IAbpAppServiceConvention, ITransientDependency + public class AbpServiceConvention : IAbpServiceConvention, ITransientDependency { private readonly AbpAspNetCoreMvcOptions _options; - public AbpAppServiceConvention(IOptions options) + public AbpServiceConvention(IOptions options) { _options = options.Value; } @@ -38,8 +38,7 @@ namespace Volo.Abp.AspNetCore.Mvc var configuration = GetControllerSettingOrNull(controllerType); //TODO: We can remove different behaviour for ImplementsRemoteServiceInterface. If there is a configuration, then it should be applied! - //TODO: If so, we can rename AppServiceControllers to ConventionalControllers! - //TODO: But also consider AbpControllerAssemblySetting.IsRemoteService method too..! + //TODO: But also consider ConventionalControllerSetting.IsRemoteService method too..! if (ImplementsRemoteServiceInterface(controllerType)) { @@ -58,7 +57,7 @@ namespace Volo.Abp.AspNetCore.Mvc } } - protected virtual void ConfigureRemoteService(ControllerModel controller, [CanBeNull] AbpControllerAssemblySetting configuration) + protected virtual void ConfigureRemoteService(ControllerModel controller, [CanBeNull] ConventionalControllerSetting configuration) { ConfigureApiExplorer(controller); ConfigureSelector(controller, configuration); @@ -95,7 +94,7 @@ namespace Volo.Abp.AspNetCore.Mvc protected virtual bool CanUseFormBodyBinding(ActionModel action, ParameterModel parameter) { - if (_options.AppServiceControllers.FormBodyBindingIgnoredTypes.Any(t => t.IsAssignableFrom(parameter.ParameterInfo.ParameterType))) + if (_options.ConventionalControllers.FormBodyBindingIgnoredTypes.Any(t => t.IsAssignableFrom(parameter.ParameterInfo.ParameterType))) { return false; } @@ -168,7 +167,7 @@ namespace Volo.Abp.AspNetCore.Mvc } } - protected virtual void ConfigureSelector(ControllerModel controller, [CanBeNull] AbpControllerAssemblySetting configuration) + protected virtual void ConfigureSelector(ControllerModel controller, [CanBeNull] ConventionalControllerSetting configuration) { RemoveEmptySelectors(controller.Selectors); @@ -185,7 +184,7 @@ namespace Volo.Abp.AspNetCore.Mvc } } - protected virtual void ConfigureSelector(string rootPath, string controllerName, ActionModel action, [CanBeNull] AbpControllerAssemblySetting configuration) + protected virtual void ConfigureSelector(string rootPath, string controllerName, ActionModel action, [CanBeNull] ConventionalControllerSetting configuration) { RemoveEmptySelectors(action.Selectors); @@ -199,7 +198,7 @@ namespace Volo.Abp.AspNetCore.Mvc } } - protected virtual void AddAbpServiceSelector(string rootPath, string controllerName, ActionModel action, [CanBeNull] AbpControllerAssemblySetting configuration) + protected virtual void AddAbpServiceSelector(string rootPath, string controllerName, ActionModel action, [CanBeNull] ConventionalControllerSetting configuration) { var httpMethod = SelectHttpMethod(action, configuration); @@ -212,12 +211,12 @@ namespace Volo.Abp.AspNetCore.Mvc action.Selectors.Add(abpServiceSelectorModel); } - protected virtual string SelectHttpMethod(ActionModel action, AbpControllerAssemblySetting configuration) + protected virtual string SelectHttpMethod(ActionModel action, ConventionalControllerSetting configuration) { return HttpMethodHelper.GetConventionalVerbForMethodName(action.ActionName); } - protected virtual void NormalizeSelectorRoutes(string rootPath, string controllerName, ActionModel action, [CanBeNull] AbpControllerAssemblySetting configuration) + protected virtual void NormalizeSelectorRoutes(string rootPath, string controllerName, ActionModel action, [CanBeNull] ConventionalControllerSetting configuration) { foreach (var selector in action.Selectors) { @@ -236,12 +235,12 @@ namespace Volo.Abp.AspNetCore.Mvc } [CanBeNull] - protected virtual AbpControllerAssemblySetting GetControllerSettingOrNull(Type controllerType) + protected virtual ConventionalControllerSetting GetControllerSettingOrNull(Type controllerType) { - return _options.AppServiceControllers.ControllerAssemblySettings.GetSettingOrNull(controllerType); + return _options.ConventionalControllers.ConventionalControllerSettings.GetSettingOrNull(controllerType); } - protected virtual AttributeRouteModel CreateAbpServiceAttributeRouteModel(string rootPath, string controllerName, ActionModel action, string httpMethod, [CanBeNull] AbpControllerAssemblySetting configuration) + protected virtual AttributeRouteModel CreateAbpServiceAttributeRouteModel(string rootPath, string controllerName, ActionModel action, string httpMethod, [CanBeNull] ConventionalControllerSetting configuration) { return new AttributeRouteModel( new RouteAttribute( @@ -250,7 +249,7 @@ namespace Volo.Abp.AspNetCore.Mvc ); } - protected virtual string CalculateRouteTemplate(string rootPath, string controllerName, ActionModel action, string httpMethod, [CanBeNull] AbpControllerAssemblySetting configuration) + protected virtual string CalculateRouteTemplate(string rootPath, string controllerName, ActionModel action, string httpMethod, [CanBeNull] ConventionalControllerSetting configuration) { var controllerNameInUrl = NormalizeUrlControllerName(rootPath, controllerName, action, httpMethod, configuration); @@ -279,7 +278,7 @@ namespace Volo.Abp.AspNetCore.Mvc return url; } - protected virtual string NormalizeUrlActionName(string rootPath, string controllerName, ActionModel action, string httpMethod, [CanBeNull] AbpControllerAssemblySetting configuration) + protected virtual string NormalizeUrlActionName(string rootPath, string controllerName, ActionModel action, string httpMethod, [CanBeNull] ConventionalControllerSetting configuration) { var actionNameInUrl = HttpMethodHelper .RemoveHttpMethodPrefix(action.ActionName, httpMethod) @@ -301,7 +300,7 @@ namespace Volo.Abp.AspNetCore.Mvc ); } - protected virtual string NormalizeUrlControllerName(string rootPath, string controllerName, ActionModel action, string httpMethod, [CanBeNull] AbpControllerAssemblySetting configuration) + protected virtual string NormalizeUrlControllerName(string rootPath, string controllerName, ActionModel action, string httpMethod, [CanBeNull] ConventionalControllerSetting configuration) { if(configuration?.UrlControllerNameNormalizer == null) { diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConventionWrapper.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpServiceConventionWrapper.cs similarity index 50% rename from src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConventionWrapper.cs rename to src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpServiceConventionWrapper.cs index c4fff972b6..10a45a659a 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConventionWrapper.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/AbpServiceConventionWrapper.cs @@ -3,16 +3,16 @@ using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.DependencyInjection; -namespace Volo.Abp.AspNetCore.Mvc +namespace Volo.Abp.AspNetCore.Mvc.Conventions { [DisableConventionalRegistration] - public class AbpAppServiceConventionWrapper : IApplicationModelConvention + public class AbpServiceConventionWrapper : IApplicationModelConvention { - private readonly Lazy _convention; + private readonly Lazy _convention; - public AbpAppServiceConventionWrapper(IServiceCollection services) + public AbpServiceConventionWrapper(IServiceCollection services) { - _convention = services.GetRequiredServiceLazy(); + _convention = services.GetRequiredServiceLazy(); } public void Apply(ApplicationModel application) diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerOptions.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerOptions.cs new file mode 100644 index 0000000000..a574716ef1 --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerOptions.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using JetBrains.Annotations; +using Microsoft.AspNetCore.Http; +using Volo.Abp.Http.Modeling; + +namespace Volo.Abp.AspNetCore.Mvc.Conventions +{ + public class ConventionalControllerOptions + { + public ConventionalControllerSettingList ConventionalControllerSettings { get; } + + public List FormBodyBindingIgnoredTypes { get; } + + public ConventionalControllerOptions() + { + ConventionalControllerSettings = new ConventionalControllerSettingList(); + + FormBodyBindingIgnoredTypes = new List + { + typeof(IFormFile) + }; + } + + public ConventionalControllerOptions Create(Assembly assembly, [CanBeNull] Action optionsAction = null) + { + var setting = new ConventionalControllerSetting(assembly, ModuleApiDescriptionModel.DefaultRootPath); + optionsAction?.Invoke(setting); + setting.Initialize(); + ConventionalControllerSettings.Add(setting); + return this; + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpControllerAssemblySetting.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSetting.cs similarity index 92% rename from src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpControllerAssemblySetting.cs rename to src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSetting.cs index a86d5d920f..10ba9b0912 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpControllerAssemblySetting.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSetting.cs @@ -9,9 +9,9 @@ using Microsoft.AspNetCore.Mvc.Versioning; using Volo.Abp.Application.Services; using Volo.Abp.Reflection; -namespace Volo.Abp.AspNetCore.Mvc +namespace Volo.Abp.AspNetCore.Mvc.Conventions { - public class AbpControllerAssemblySetting + public class ConventionalControllerSetting { [NotNull] public Assembly Assembly { get; } @@ -47,7 +47,7 @@ namespace Volo.Abp.AspNetCore.Mvc public Action ApiVersionConfigurer { get; set; } - public AbpControllerAssemblySetting([NotNull] Assembly assembly, [NotNull] string rootPath) + public ConventionalControllerSetting([NotNull] Assembly assembly, [NotNull] string rootPath) { Check.NotNull(assembly, rootPath); diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ControllerAssemblySettingList.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSettingList.cs similarity index 55% rename from src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ControllerAssemblySettingList.cs rename to src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSettingList.cs index b59ac8c576..a460a8fe00 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ControllerAssemblySettingList.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSettingList.cs @@ -3,12 +3,12 @@ using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; -namespace Volo.Abp.AspNetCore.Mvc +namespace Volo.Abp.AspNetCore.Mvc.Conventions { - public class ControllerAssemblySettingList : List + public class ConventionalControllerSettingList : List { [CanBeNull] - public AbpControllerAssemblySetting GetSettingOrNull(Type controllerType) + public ConventionalControllerSetting GetSettingOrNull(Type controllerType) { return this.FirstOrDefault(controllerSetting => controllerSetting.ControllerTypes.Contains(controllerType)); } diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/IAbpServiceConvention.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/IAbpServiceConvention.cs new file mode 100644 index 0000000000..aac601d0b4 --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/IAbpServiceConvention.cs @@ -0,0 +1,8 @@ +using Microsoft.AspNetCore.Mvc.ApplicationModels; + +namespace Volo.Abp.AspNetCore.Mvc.Conventions +{ + public interface IAbpServiceConvention : IApplicationModelConvention + { + } +} \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/UrlActionNameNormalizerContext.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/UrlActionNameNormalizerContext.cs similarity index 93% rename from src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/UrlActionNameNormalizerContext.cs rename to src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/UrlActionNameNormalizerContext.cs index 631b8b50de..ebc122af05 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/UrlActionNameNormalizerContext.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/UrlActionNameNormalizerContext.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Mvc.ApplicationModels; -namespace Volo.Abp.AspNetCore.Mvc +namespace Volo.Abp.AspNetCore.Mvc.Conventions { public class UrlActionNameNormalizerContext { diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/UrlControllerNameNormalizerContext.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/UrlControllerNameNormalizerContext.cs similarity index 87% rename from src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/UrlControllerNameNormalizerContext.cs rename to src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/UrlControllerNameNormalizerContext.cs index aad40fe4d7..2cb3bdc733 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/UrlControllerNameNormalizerContext.cs +++ b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/UrlControllerNameNormalizerContext.cs @@ -1,4 +1,4 @@ -namespace Volo.Abp.AspNetCore.Mvc +namespace Volo.Abp.AspNetCore.Mvc.Conventions { public class UrlControllerNameNormalizerContext { diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/IAbpAppServiceConvention.cs b/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/IAbpAppServiceConvention.cs deleted file mode 100644 index 899d66b4c2..0000000000 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/IAbpAppServiceConvention.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Microsoft.AspNetCore.Mvc.ApplicationModels; - -namespace Volo.Abp.AspNetCore.Mvc -{ - public interface IAbpAppServiceConvention : IApplicationModelConvention - { - } -} \ No newline at end of file diff --git a/src/Volo.Abp.Identity.HttpApi.Host/AbpIdentityHttpApiHostModule.cs b/src/Volo.Abp.Identity.HttpApi.Host/AbpIdentityHttpApiHostModule.cs index b826251fa2..db1f278d6b 100644 --- a/src/Volo.Abp.Identity.HttpApi.Host/AbpIdentityHttpApiHostModule.cs +++ b/src/Volo.Abp.Identity.HttpApi.Host/AbpIdentityHttpApiHostModule.cs @@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.EntityFrameworkCore; -using Microsoft.Examples; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -90,12 +89,12 @@ namespace Volo.Abp.Identity.HttpApi.Host services.Configure(options => { - options.AppServiceControllers.Create(typeof(AbpIdentityHttpApiHostModule).Assembly, o => + options.ConventionalControllers.Create(typeof(AbpIdentityHttpApiHostModule).Assembly, o => { o.TypePredicate = t => t == typeof(CallsController); }); - options.AppServiceControllers.Create(typeof(AbpIdentityHttpApiHostModule).Assembly, o => + options.ConventionalControllers.Create(typeof(AbpIdentityHttpApiHostModule).Assembly, o => { o.TypePredicate = t => t == typeof(Host.VersioningTests.V2.CallsController); o.RootPath = "app/compat"; diff --git a/src/Volo.Abp.Identity.HttpApi.Host/SwaggerDefaultValues.cs b/src/Volo.Abp.Identity.HttpApi.Host/SwaggerDefaultValues.cs index 11045d85a6..f273dced70 100644 --- a/src/Volo.Abp.Identity.HttpApi.Host/SwaggerDefaultValues.cs +++ b/src/Volo.Abp.Identity.HttpApi.Host/SwaggerDefaultValues.cs @@ -1,9 +1,9 @@ -namespace Microsoft.Examples -{ - using Swashbuckle.AspNetCore.Swagger; - using Swashbuckle.AspNetCore.SwaggerGen; - using System.Linq; +using System.Linq; +using Swashbuckle.AspNetCore.Swagger; +using Swashbuckle.AspNetCore.SwaggerGen; +namespace Volo.Abp.Identity.HttpApi.Host +{ /// /// Represents the Swagger/Swashbuckle operation filter used to document the implicit API version parameter. /// diff --git a/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/AbpIdentityHttpApiModule.cs b/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/AbpIdentityHttpApiModule.cs index 195ce009b7..5f9c285c9f 100644 --- a/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/AbpIdentityHttpApiModule.cs +++ b/src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/AbpIdentityHttpApiModule.cs @@ -15,14 +15,14 @@ namespace Volo.Abp.Identity services.Configure(options => { - options.AppServiceControllers.Create(typeof(AbpIdentityApplicationModule).Assembly, opts => + options.ConventionalControllers.Create(typeof(AbpIdentityApplicationModule).Assembly, opts => { opts.RootPath = "identity"; opts.UrlControllerNameNormalizer = context => context.ControllerName.RemovePreFix("Identity"); opts.ApiVersions.Add(new ApiVersion(2, 0)); }); - options.AppServiceControllers.Create(typeof(AbpIdentityHttpApiModule).Assembly); + options.ConventionalControllers.Create(typeof(AbpIdentityHttpApiModule).Assembly); }); } } diff --git a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs index 15b8727063..5e2e8e2986 100644 --- a/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs +++ b/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs @@ -24,7 +24,7 @@ namespace Volo.Abp.AspNetCore.Mvc services.Configure(options => { - options.AppServiceControllers.Create(typeof(TestAppModule).Assembly, opts => + options.ConventionalControllers.Create(typeof(TestAppModule).Assembly, opts => { opts.UrlActionNameNormalizer = context => string.Equals(context.ActionNameInUrl, "phone", StringComparison.OrdinalIgnoreCase) diff --git a/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AbpAspNetCoreMvcVersioningTestModule.cs b/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AbpAspNetCoreMvcVersioningTestModule.cs index 68a50f8416..ad035e8edd 100644 --- a/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AbpAspNetCoreMvcVersioningTestModule.cs +++ b/test/Volo.Abp.AspNetCore.Mvc.Versioning.Tests/Volo/Abp/AspNetCore/Mvc/Versioning/AbpAspNetCoreMvcVersioningTestModule.cs @@ -25,14 +25,14 @@ namespace Volo.Abp.AspNetCore.Mvc.Versioning services.Configure(options => { //2.0 Version - options.AppServiceControllers.Create(typeof(AbpAspNetCoreMvcVersioningTestModule).Assembly, opts => + options.ConventionalControllers.Create(typeof(AbpAspNetCoreMvcVersioningTestModule).Assembly, opts => { opts.TypePredicate = t => t.Namespace == typeof(Volo.Abp.AspNetCore.Mvc.Versioning.App.TodoAppService).Namespace; opts.ApiVersions.Add(new ApiVersion(2, 0)); }); //1.0 Compatability version - options.AppServiceControllers.Create(typeof(AbpAspNetCoreMvcVersioningTestModule).Assembly, opts => + options.ConventionalControllers.Create(typeof(AbpAspNetCoreMvcVersioningTestModule).Assembly, opts => { opts.TypePredicate = t => t.Namespace == typeof(Volo.Abp.AspNetCore.Mvc.Versioning.App.Compat.TodoAppService).Namespace; opts.ApiVersions.Add(new ApiVersion(1, 0));