Browse Source
Support for exporting generic interfaces.
pull/12094/head
maliming
4 years ago
No known key found for this signature in database
GPG Key ID: 96224957E51C89E
2 changed files with
30 additions and
1 deletions
-
framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/ExposeServicesAttribute.cs
-
framework/test/Volo.Abp.Core.Tests/Volo/Abp/DependencyInjection/AutoRegistrationHelper_Tests.cs
|
|
|
@ -15,7 +15,7 @@ public class ExposeServicesAttribute : Attribute, IExposedServiceTypesProvider |
|
|
|
|
|
|
|
public ExposeServicesAttribute(params Type[] serviceTypes) |
|
|
|
{ |
|
|
|
ServiceTypes = serviceTypes ?? new Type[0]; |
|
|
|
ServiceTypes = serviceTypes ?? Type.EmptyTypes; |
|
|
|
} |
|
|
|
|
|
|
|
public Type[] GetExposedServiceTypes(Type targetType) |
|
|
|
@ -49,6 +49,10 @@ public class ExposeServicesAttribute : Attribute, IExposedServiceTypesProvider |
|
|
|
foreach (var interfaceType in type.GetTypeInfo().GetInterfaces()) |
|
|
|
{ |
|
|
|
var interfaceName = interfaceType.Name; |
|
|
|
if (interfaceType.IsGenericType) |
|
|
|
{ |
|
|
|
interfaceName = interfaceType.Name.Left(interfaceType.Name.IndexOf('`')); |
|
|
|
} |
|
|
|
|
|
|
|
if (interfaceName.StartsWith("I")) |
|
|
|
{ |
|
|
|
|
|
|
|
@ -33,6 +33,21 @@ public class AutoRegistrationHelper_Tests |
|
|
|
exposedServices.ShouldContain(typeof(IDerivedService)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Get_Conventional_Exposed_Generic_Types_By_Default() |
|
|
|
{ |
|
|
|
//Act
|
|
|
|
var exposedServices = ExposedServiceExplorer.GetExposedServices(typeof(DefaultGenericService)); |
|
|
|
|
|
|
|
//Assert
|
|
|
|
exposedServices.Count.ShouldBe(4); |
|
|
|
exposedServices.ShouldContain(typeof(IService)); |
|
|
|
exposedServices.ShouldContain(typeof(IGenericService<string>)); |
|
|
|
exposedServices.ShouldContain(typeof(IGenericService<int>)); |
|
|
|
exposedServices.ShouldContain(typeof(DefaultGenericService)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class DefaultDerivedService : IDerivedService |
|
|
|
{ |
|
|
|
} |
|
|
|
@ -50,4 +65,14 @@ public class AutoRegistrationHelper_Tests |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public interface IGenericService<T> |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public class DefaultGenericService : IService, IGenericService<string>, IGenericService<int> |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|