Improvements on versioning

pull/122/head
Halil İbrahim Kalkan 7 years ago
parent 01fead68a5
commit 7ab0422748

@ -2,8 +2,6 @@ using System.Reflection;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Volo.Abp.Application.Services;
using Volo.Abp.Reflection;
namespace Volo.Abp.AspNetCore.Mvc
{
@ -18,29 +16,14 @@ namespace Volo.Abp.AspNetCore.Mvc
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.
var configuration = _application.ServiceProvider
.GetRequiredService<IOptions<AbpAspNetCoreMvcOptions>>().Value
.AppServiceControllers
.ControllerAssemblySettings
.GetSettingOrNull(type);
.GetSettingOrNull(typeInfo.AsType());
return configuration != null && (configuration.TypePredicate == null || configuration.TypePredicate(type));
return configuration != null;
}
}
}

@ -37,11 +37,14 @@ namespace Volo.Abp.AspNetCore.Mvc
var controllerType = controller.ControllerType.AsType();
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);
configuration?.ControllerModelConfigurer?.Invoke(controller);
//ConfigureArea(controller, configuration);
ConfigureRemoteService(controller, configuration);
}
else
@ -328,7 +331,7 @@ namespace Volo.Abp.AspNetCore.Mvc
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);
}

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

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

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

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

Loading…
Cancel
Save