mirror of https://github.com/abpframework/abp.git
9 changed files with 139 additions and 42 deletions
@ -0,0 +1,41 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Reflection; |
|||
using Microsoft.AspNetCore.Http; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc |
|||
{ |
|||
public class AppServiceControllerOptions |
|||
{ |
|||
public ControllerAssemblySettingList ControllerAssemblySettings { get; } |
|||
|
|||
public List<Type> FormBodyBindingIgnoredTypes { get; } |
|||
|
|||
public List<IUrlActionNameNormalizer> UrlActionNameNormalizers { get; } |
|||
|
|||
public AppServiceControllerOptions() |
|||
{ |
|||
ControllerAssemblySettings = new ControllerAssemblySettingList(); |
|||
|
|||
FormBodyBindingIgnoredTypes = new List<Type> |
|||
{ |
|||
typeof(IFormFile) |
|||
}; |
|||
|
|||
UrlActionNameNormalizers = new List<IUrlActionNameNormalizer> |
|||
{ |
|||
new DefaultUrlActionNameNormalizer() |
|||
}; |
|||
} |
|||
|
|||
public AbpControllerAssemblySettingBuilder CreateFor( |
|||
Assembly assembly, |
|||
string moduleName = AbpControllerAssemblySetting.DefaultServiceModuleName, |
|||
bool useConventionalHttpVerbs = true) |
|||
{ |
|||
var setting = new AbpControllerAssemblySetting(moduleName, assembly, useConventionalHttpVerbs); |
|||
ControllerAssemblySettings.Add(setting); |
|||
return new AbpControllerAssemblySettingBuilder(setting); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using System; |
|||
using Volo.Abp.Http; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc |
|||
{ |
|||
public class DefaultUrlActionNameNormalizer : IUrlActionNameNormalizer |
|||
{ |
|||
public void Normalize(UrlActionNameNormalizerContext context) |
|||
{ |
|||
if (context.ActionNameInUrl.IsNullOrEmpty()) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
context.ActionNameInUrl = HttpMethodConventionHelper.RemoveHttpMethodPrefix(context.ActionNameInUrl, context.HttpMethod); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.AspNetCore.Mvc |
|||
{ |
|||
public interface IUrlActionNameNormalizer |
|||
{ |
|||
void Normalize(UrlActionNameNormalizerContext context); |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
using Microsoft.AspNetCore.Mvc.ApplicationModels; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc |
|||
{ |
|||
public class UrlActionNameNormalizerContext |
|||
{ |
|||
public string ModuleName { get; } |
|||
|
|||
public string ControllerName { get; } |
|||
|
|||
public ActionModel Action { get; } |
|||
|
|||
public string HttpMethod { get; } |
|||
|
|||
public string ActionNameInUrl { get; set; } |
|||
|
|||
public UrlActionNameNormalizerContext(string moduleName, string controllerName, ActionModel action, string httpMethod, string actionNameInUrl) |
|||
{ |
|||
ModuleName = moduleName; |
|||
ControllerName = controllerName; |
|||
Action = action; |
|||
HttpMethod = httpMethod; |
|||
|
|||
ActionNameInUrl = actionNameInUrl; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using System; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
|
|||
namespace Volo.Abp.AspNetCore.App |
|||
{ |
|||
public class PhoneBookUrlActionNameNormalizer : IUrlActionNameNormalizer |
|||
{ |
|||
public void Normalize(UrlActionNameNormalizerContext context) |
|||
{ |
|||
if (string.Equals(context.ActionNameInUrl, "phone", StringComparison.OrdinalIgnoreCase)) |
|||
{ |
|||
context.ActionNameInUrl = "phones"; |
|||
return; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue