Browse Source

Improvements on versioning

pull/122/head
Halil İbrahim Kalkan 9 years ago
parent
commit
7ab0422748
  1. 21
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceControllerFeatureProvider.cs
  2. 9
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceConvention.cs
  3. 17
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpControllerAssemblySetting.cs
  4. 2
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs
  5. 2
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ControllerAssemblySettingList.cs
  6. 4
      src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/AbpIdentityHttpApiModule.cs

21
src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAppServiceControllerFeatureProvider.cs

@ -2,8 +2,6 @@ using System.Reflection;
using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.Application.Services;
using Volo.Abp.Reflection;
namespace Volo.Abp.AspNetCore.Mvc namespace Volo.Abp.AspNetCore.Mvc
{ {
@ -18,29 +16,14 @@ namespace Volo.Abp.AspNetCore.Mvc
protected override bool IsController(TypeInfo typeInfo) protected override bool IsController(TypeInfo typeInfo)
{ {
var type = typeInfo.AsType();
if (!typeof(IRemoteService).IsAssignableFrom(type) ||
!typeInfo.IsPublic || typeInfo.IsAbstract || typeInfo.IsGenericType)
{
return false;
}
var remoteServiceAttr = ReflectionHelper.GetSingleAttributeOrDefault<RemoteServiceAttribute>(typeInfo);
if (remoteServiceAttr != null && !remoteServiceAttr.IsEnabledFor(type))
{
return false;
}
//TODO: Move this to a lazy loaded field for efficiency. //TODO: Move this to a lazy loaded field for efficiency.
var configuration = _application.ServiceProvider var configuration = _application.ServiceProvider
.GetRequiredService<IOptions<AbpAspNetCoreMvcOptions>>().Value .GetRequiredService<IOptions<AbpAspNetCoreMvcOptions>>().Value
.AppServiceControllers .AppServiceControllers
.ControllerAssemblySettings .ControllerAssemblySettings
.GetSettingOrNull(type); .GetSettingOrNull(typeInfo.AsType());
return configuration != null && (configuration.TypePredicate == null || configuration.TypePredicate(type)); return configuration != null;
} }
} }
} }

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

@ -37,11 +37,14 @@ namespace Volo.Abp.AspNetCore.Mvc
var controllerType = controller.ControllerType.AsType(); var controllerType = controller.ControllerType.AsType();
var configuration = GetControllerSettingOrNull(controllerType); var configuration = GetControllerSettingOrNull(controllerType);
if (IsRemoteService(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..!
if (ImplementsRemoteServiceInterface(controllerType))
{ {
controller.ControllerName = controller.ControllerName.RemovePostFix(ApplicationService.CommonPostfixes); controller.ControllerName = controller.ControllerName.RemovePostFix(ApplicationService.CommonPostfixes);
configuration?.ControllerModelConfigurer?.Invoke(controller); configuration?.ControllerModelConfigurer?.Invoke(controller);
//ConfigureArea(controller, configuration);
ConfigureRemoteService(controller, configuration); ConfigureRemoteService(controller, configuration);
} }
else else
@ -328,7 +331,7 @@ namespace Volo.Abp.AspNetCore.Mvc
return selector.AttributeRouteModel == null && selector.ActionConstraints.IsNullOrEmpty(); return selector.AttributeRouteModel == null && selector.ActionConstraints.IsNullOrEmpty();
} }
protected virtual bool IsRemoteService(Type controllerType) protected virtual bool ImplementsRemoteServiceInterface(Type controllerType)
{ {
return typeof(IRemoteService).GetTypeInfo().IsAssignableFrom(controllerType); return typeof(IRemoteService).GetTypeInfo().IsAssignableFrom(controllerType);
} }

17
src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpControllerAssemblySetting.cs

@ -16,7 +16,7 @@ namespace Volo.Abp.AspNetCore.Mvc
public Assembly Assembly { get; } public Assembly Assembly { get; }
[NotNull] [NotNull]
public List<Type> ControllerTypes { get; } public HashSet<Type> ControllerTypes { get; }
[NotNull] [NotNull]
public string RootPath public string RootPath
@ -51,18 +51,21 @@ namespace Volo.Abp.AspNetCore.Mvc
Assembly = assembly; Assembly = assembly;
RootPath = rootPath; RootPath = rootPath;
ControllerTypes = new List<Type>(); ControllerTypes = new HashSet<Type>();
ApiVersion = new ApiVersion(1, 0); ApiVersion = new ApiVersion(1, 0);
} }
public void Initialize() public void Initialize()
{ {
ControllerTypes.AddRange( var types = Assembly.GetTypes()
Assembly.GetTypes() .Where(IsRemoteService)
.Where(IsRemoteService) .WhereIf(TypePredicate != null, TypePredicate);
.WhereIf(TypePredicate != null, TypePredicate)
); foreach (var type in types)
{
ControllerTypes.Add(type);
}
} }
private static bool IsRemoteService(Type type) private static bool IsRemoteService(Type type)

2
src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs

@ -164,7 +164,7 @@ namespace Volo.Abp.AspNetCore.Mvc
foreach (var controllerSetting in _options.AppServiceControllers.ControllerAssemblySettings) foreach (var controllerSetting in _options.AppServiceControllers.ControllerAssemblySettings)
{ {
if (Equals(controllerType.Assembly, controllerSetting.Assembly)) if(controllerSetting.ControllerTypes.Contains(controllerType))
{ {
return controllerSetting.RootPath; return controllerSetting.RootPath;
} }

2
src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ControllerAssemblySettingList.cs

@ -10,7 +10,7 @@ namespace Volo.Abp.AspNetCore.Mvc
[CanBeNull] [CanBeNull]
public AbpControllerAssemblySetting GetSettingOrNull(Type controllerType) public AbpControllerAssemblySetting GetSettingOrNull(Type controllerType)
{ {
return this.FirstOrDefault(controllerSetting => controllerSetting.Assembly == controllerType.Assembly); return this.FirstOrDefault(controllerSetting => controllerSetting.ControllerTypes.Contains(controllerType));
} }
} }
} }

4
src/Volo.Abp.Identity.HttpApi/Volo/Abp/Identity/AbpIdentityHttpApiModule.cs

@ -1,5 +1,4 @@
using System; using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
@ -19,7 +18,8 @@ namespace Volo.Abp.Identity
{ {
opts.RootPath = "identity"; opts.RootPath = "identity";
opts.UrlControllerNameNormalizer = context => context.ControllerName.RemovePreFix("Identity"); opts.UrlControllerNameNormalizer = context => context.ControllerName.RemovePreFix("Identity");
opts.ApiVersion = new ApiVersion(2, 0, "beta");
//
}); });
}); });
} }

Loading…
Cancel
Save