Browse Source

Refactored.

pull/96/head
Halil İbrahim Kalkan 9 years ago
parent
commit
66dea810de
  1. 43
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConvention.cs
  2. 2
      src/Volo.Abp/Volo/Abp/Application/Services/ApplicationService.cs

43
src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConvention.cs

@ -25,24 +25,28 @@ namespace Volo.Abp.AspNetCore.Mvc
} }
public void Apply(ApplicationModel application) public void Apply(ApplicationModel application)
{
ApplyForControllers(application);
}
protected virtual void ApplyForControllers(ApplicationModel application)
{ {
foreach (var controller in application.Controllers) foreach (var controller in application.Controllers)
{ {
var type = controller.ControllerType.AsType(); var controllerType = controller.ControllerType.AsType();
var configuration = GetControllerSettingOrNull(type); var configuration = GetControllerSettingOrNull(controllerType);
if (typeof(IApplicationService).GetTypeInfo().IsAssignableFrom(type)) if (IsApplicationService(controllerType))
{ {
controller.ControllerName = controller.ControllerName.RemovePostFix(ApplicationService.CommonPostfixes); controller.ControllerName = controller.ControllerName.RemovePostFix(ApplicationService.CommonPostfixes);
configuration?.ControllerModelConfigurer(controller); configuration?.ControllerModelConfigurer(controller);
ConfigureArea(controller, configuration); ConfigureArea(controller, configuration);
ConfigureRemoteService(controller, configuration); ConfigureRemoteService(controller, configuration);
} }
else else
{ {
var remoteServiceAtt = ReflectionHelper.GetSingleAttributeOrDefault<RemoteServiceAttribute>(type.GetTypeInfo()); var remoteServiceAttr = ReflectionHelper.GetSingleAttributeOrDefault<RemoteServiceAttribute>(controllerType.GetTypeInfo());
if (remoteServiceAtt != null && remoteServiceAtt.IsEnabledFor(type)) if (remoteServiceAttr != null && remoteServiceAttr.IsEnabledFor(controllerType))
{ {
ConfigureRemoteService(controller, configuration); ConfigureRemoteService(controller, configuration);
} }
@ -202,28 +206,32 @@ namespace Volo.Abp.AspNetCore.Mvc
protected virtual void AddAbpServiceSelector(string moduleName, string controllerName, ActionModel action, [CanBeNull] AbpControllerAssemblySetting configuration) protected virtual void AddAbpServiceSelector(string moduleName, string controllerName, ActionModel action, [CanBeNull] AbpControllerAssemblySetting configuration)
{ {
var verb = configuration?.UseConventionalHttpVerbs == true var httpMethod = SelectHttpMethod(action, configuration);
? HttpVerbHelper.GetConventionalVerbForMethodName(action.ActionName)
: HttpVerbHelper.DefaultHttpVerb;
var abpServiceSelectorModel = new SelectorModel var abpServiceSelectorModel = new SelectorModel
{ {
AttributeRouteModel = CreateAbpServiceAttributeRouteModel(moduleName, controllerName, action, verb), AttributeRouteModel = CreateAbpServiceAttributeRouteModel(moduleName, controllerName, action, httpMethod),
ActionConstraints = { new HttpMethodActionConstraint(new[] { verb }) } ActionConstraints = { new HttpMethodActionConstraint(new[] { httpMethod }) }
}; };
action.Selectors.Add(abpServiceSelectorModel); action.Selectors.Add(abpServiceSelectorModel);
} }
protected virtual string SelectHttpMethod(ActionModel action, AbpControllerAssemblySetting configuration)
{
return configuration?.UseConventionalHttpVerbs == true
? HttpVerbHelper.GetConventionalVerbForMethodName(action.ActionName)
: HttpVerbHelper.DefaultHttpVerb;
}
protected virtual void NormalizeSelectorRoutes(string moduleName, string controllerName, ActionModel action) protected virtual void NormalizeSelectorRoutes(string moduleName, string controllerName, ActionModel action)
{ {
foreach (var selector in action.Selectors) foreach (var selector in action.Selectors)
{ {
//TODO: Revise this? var httpMethod = selector.ActionConstraints.OfType<HttpMethodActionConstraint>().FirstOrDefault()?.HttpMethods?.FirstOrDefault();
var method = selector.ActionConstraints.OfType<HttpMethodActionConstraint>().FirstOrDefault()?.HttpMethods?.FirstOrDefault();
if (selector.AttributeRouteModel == null) if (selector.AttributeRouteModel == null)
{ {
selector.AttributeRouteModel = CreateAbpServiceAttributeRouteModel(moduleName, controllerName, action, method); selector.AttributeRouteModel = CreateAbpServiceAttributeRouteModel(moduleName, controllerName, action, httpMethod);
} }
} }
} }
@ -240,7 +248,7 @@ namespace Volo.Abp.AspNetCore.Mvc
return _options.ControllerAssemblySettings.GetSettingOrNull(controllerType); return _options.ControllerAssemblySettings.GetSettingOrNull(controllerType);
} }
protected virtual AttributeRouteModel CreateAbpServiceAttributeRouteModel(string moduleName, string controllerName, ActionModel action, string verb) protected virtual AttributeRouteModel CreateAbpServiceAttributeRouteModel(string moduleName, string controllerName, ActionModel action, string httpMethod)
{ {
var url = $"api/services/{moduleName}/{controllerName}/{action.ActionName}"; var url = $"api/services/{moduleName}/{controllerName}/{action.ActionName}";
return new AttributeRouteModel(new RouteAttribute(url)); return new AttributeRouteModel(new RouteAttribute(url));
@ -258,5 +266,10 @@ namespace Volo.Abp.AspNetCore.Mvc
{ {
return selector.AttributeRouteModel == null && selector.ActionConstraints.IsNullOrEmpty(); return selector.AttributeRouteModel == null && selector.ActionConstraints.IsNullOrEmpty();
} }
protected virtual bool IsApplicationService(Type controllerType)
{
return typeof(IApplicationService).GetTypeInfo().IsAssignableFrom(controllerType);
}
} }
} }

2
src/Volo.Abp/Volo/Abp/Application/Services/ApplicationService.cs

@ -2,7 +2,7 @@ namespace Volo.Abp.Application.Services
{ {
public abstract class ApplicationService : AbpServiceBase, IApplicationService public abstract class ApplicationService : AbpServiceBase, IApplicationService
{ {
public static string[] CommonPostfixes = { "AppService", "ApplicationService", "Service" }; public static string[] CommonPostfixes { get; set; } = { "AppService", "ApplicationService", "Service" };
/* Will be added when implemented /* Will be added when implemented
- AbpSession - AbpSession

Loading…
Cancel
Save