Browse Source

Accept inherited IntegrationServiceAttribute too.

pull/14051/head
Halil İbrahim Kalkan 4 years ago
parent
commit
c542c1bb81
  1. 9
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Auditing/AbpAuditActionFilter.cs
  2. 4
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSetting.cs
  3. 2
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalRouteBuilder.cs
  4. 3
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingInterceptorRegistrar.cs
  5. 25
      framework/src/Volo.Abp.Core/Volo/Abp/IntegrationServiceAttribute.cs
  6. 4
      framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionHttpClientProxyExtensions.cs
  7. 48
      framework/test/Volo.Abp.Core.Tests/Volo/Abp/IntegrationServiceAttribute_Tests.cs

9
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Auditing/AbpAuditActionFilter.cs

@ -93,10 +93,11 @@ public class AbpAuditActionFilter : IAsyncActionFilter, ITransientDependency
ActionDescriptor actionDescriptor)
{
if (!abpAuditingOptions.IsEnabledForIntegrationServices &&
actionDescriptor
.AsControllerActionDescriptor()
.ControllerTypeInfo
.IsDefined(typeof(IntegrationServiceAttribute), true))
IntegrationServiceAttribute.IsDefinedOrInherited(
actionDescriptor
.AsControllerActionDescriptor()
.ControllerTypeInfo)
)
{
return false;
}

4
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSetting.cs

@ -122,12 +122,12 @@ public class ConventionalControllerSetting
{
if (ApplicationServiceTypes == ApplicationServiceTypes.ApplicationServices)
{
return !type.IsDefined(typeof(IntegrationServiceAttribute));
return !IntegrationServiceAttribute.IsDefinedOrInherited(type);
}
if (ApplicationServiceTypes == ApplicationServiceTypes.IntegrationServices)
{
return type.IsDefined(typeof(IntegrationServiceAttribute));
return IntegrationServiceAttribute.IsDefinedOrInherited(type);
}
return true;

2
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalRouteBuilder.cs

@ -73,7 +73,7 @@ public class ConventionalRouteBuilder : IConventionalRouteBuilder, ITransientDep
protected virtual string GetApiRoutePrefix(ActionModel actionModel, ConventionalControllerSetting configuration)
{
if (actionModel.Controller.ControllerType.IsDefined(typeof(IntegrationServiceAttribute), true))
if (IntegrationServiceAttribute.IsDefinedOrInherited(actionModel.Controller.ControllerType))
{
return AbpAspNetCoreConsts.DefaultIntegrationServiceApiPrefix;
}

3
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingInterceptorRegistrar.cs

@ -52,7 +52,8 @@ public static class AuditingInterceptorRegistrar
if (typeof(IAuditingEnabled).IsAssignableFrom(type))
{
if (ignoreIntegrationServiceAttribute || !type.IsDefined(typeof(IntegrationServiceAttribute), true))
if (ignoreIntegrationServiceAttribute ||
!IntegrationServiceAttribute.IsDefinedOrInherited(type))
{
return true;
}

25
framework/src/Volo.Abp.Core/Volo/Abp/IntegrationServiceAttribute.cs

@ -2,8 +2,29 @@
namespace Volo.Abp;
[AttributeUsage(AttributeTargets.Class)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)]
public class IntegrationServiceAttribute : Attribute
{
public static bool IsDefinedOrInherited<T>()
{
return IsDefinedOrInherited(typeof(T));
}
public static bool IsDefinedOrInherited(Type type)
{
if (type.IsDefined(typeof(IntegrationServiceAttribute), true))
{
return true;
}
foreach (var @interface in type.GetInterfaces())
{
if (@interface.IsDefined(typeof(IntegrationServiceAttribute), true))
{
return true;
}
}
return false;
}
}

4
framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionHttpClientProxyExtensions.cs

@ -258,12 +258,12 @@ public static class ServiceCollectionHttpClientProxyExtensions
if (applicationServiceTypes == ApplicationServiceTypes.ApplicationServices)
{
return !type.IsDefined(typeof(IntegrationServiceAttribute));
return !IntegrationServiceAttribute.IsDefinedOrInherited(type);
}
if (applicationServiceTypes == ApplicationServiceTypes.IntegrationServices)
{
return type.IsDefined(typeof(IntegrationServiceAttribute));
return IntegrationServiceAttribute.IsDefinedOrInherited(type);
}
return true;

48
framework/test/Volo.Abp.Core.Tests/Volo/Abp/IntegrationServiceAttribute_Tests.cs

@ -0,0 +1,48 @@
using Shouldly;
using Xunit;
namespace Volo.Abp;
public class IntegrationServiceAttribute_Tests
{
[Fact]
public static void IsDefinedOrInherited()
{
// True cases
IntegrationServiceAttribute
.IsDefinedOrInherited<IMyIntegrationService1>()
.ShouldBeTrue();
IntegrationServiceAttribute
.IsDefinedOrInherited<MyIntegrationService1>()
.ShouldBeTrue();
IntegrationServiceAttribute
.IsDefinedOrInherited<MyIntegrationService2>()
.ShouldBeTrue();
// False cases
IntegrationServiceAttribute
.IsDefinedOrInherited<IMyIntegrationService2>()
.ShouldBeFalse();
IntegrationServiceAttribute
.IsDefinedOrInherited<MyApplicationService>()
.ShouldBeFalse();
}
[IntegrationService]
private interface IMyIntegrationService1 { }
private class MyIntegrationService1 : IMyIntegrationService1 { }
private interface IMyIntegrationService2 { }
[IntegrationService]
private class MyIntegrationService2 : IMyIntegrationService2 { }
private interface IMyApplicationService { }
private class MyApplicationService : IMyApplicationService { }
}
Loading…
Cancel
Save