diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Auditing/AbpAuditActionFilter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Auditing/AbpAuditActionFilter.cs index dfffeea5b4..954a0bd6c7 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Auditing/AbpAuditActionFilter.cs +++ b/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; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSetting.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSetting.cs index 787940cc1a..bb059a6674 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalControllerSetting.cs +++ b/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; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalRouteBuilder.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalRouteBuilder.cs index 0906d46006..f9c31467b5 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Conventions/ConventionalRouteBuilder.cs +++ b/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; } diff --git a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingInterceptorRegistrar.cs b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingInterceptorRegistrar.cs index db5d44cec5..ca07c75516 100644 --- a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingInterceptorRegistrar.cs +++ b/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; } diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/IntegrationServiceAttribute.cs b/framework/src/Volo.Abp.Core/Volo/Abp/IntegrationServiceAttribute.cs index 016a7a49c7..22ab4ca9e9 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/IntegrationServiceAttribute.cs +++ b/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() + { + 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; + } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionHttpClientProxyExtensions.cs b/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionHttpClientProxyExtensions.cs index 35c5467f78..2f7942fabe 100644 --- a/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionHttpClientProxyExtensions.cs +++ b/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; diff --git a/framework/test/Volo.Abp.Core.Tests/Volo/Abp/IntegrationServiceAttribute_Tests.cs b/framework/test/Volo.Abp.Core.Tests/Volo/Abp/IntegrationServiceAttribute_Tests.cs new file mode 100644 index 0000000000..aa2d9d578a --- /dev/null +++ b/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() + .ShouldBeTrue(); + + IntegrationServiceAttribute + .IsDefinedOrInherited() + .ShouldBeTrue(); + + IntegrationServiceAttribute + .IsDefinedOrInherited() + .ShouldBeTrue(); + + // False cases + + IntegrationServiceAttribute + .IsDefinedOrInherited() + .ShouldBeFalse(); + + IntegrationServiceAttribute + .IsDefinedOrInherited() + .ShouldBeFalse(); + + } + + [IntegrationService] + private interface IMyIntegrationService1 { } + private class MyIntegrationService1 : IMyIntegrationService1 { } + + private interface IMyIntegrationService2 { } + [IntegrationService] + private class MyIntegrationService2 : IMyIntegrationService2 { } + + private interface IMyApplicationService { } + private class MyApplicationService : IMyApplicationService { } +} +