mirror of https://github.com/abpframework/abp.git
5 changed files with 56 additions and 58 deletions
@ -1,53 +0,0 @@ |
|||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.Linq; |
|
||||
using System.Reflection; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
|
|
||||
namespace Volo.Abp.DependencyInjection |
|
||||
{ |
|
||||
public static class AutoRegistrationHelper |
|
||||
{ |
|
||||
public static List<Type> GetExposedServices(IServiceCollection services, Type type) |
|
||||
{ |
|
||||
var typeInfo = type.GetTypeInfo(); |
|
||||
|
|
||||
var customExposedServices = typeInfo |
|
||||
.GetCustomAttributes() |
|
||||
.OfType<IExposedServiceTypesProvider>() |
|
||||
.SelectMany(p => p.GetExposedServiceTypes(type)) |
|
||||
.ToList(); |
|
||||
|
|
||||
if (customExposedServices.Any()) |
|
||||
{ |
|
||||
return customExposedServices; |
|
||||
} |
|
||||
|
|
||||
return GetDefaultExposedServices(type); |
|
||||
} |
|
||||
|
|
||||
private static List<Type> GetDefaultExposedServices(Type type) |
|
||||
{ |
|
||||
var serviceTypes = new List<Type>(); |
|
||||
|
|
||||
serviceTypes.Add(type); |
|
||||
|
|
||||
foreach (var interfaceType in type.GetTypeInfo().GetInterfaces()) |
|
||||
{ |
|
||||
var interfaceName = interfaceType.Name; |
|
||||
|
|
||||
if (interfaceName.StartsWith("I")) |
|
||||
{ |
|
||||
interfaceName = interfaceName.Right(interfaceName.Length - 1); |
|
||||
} |
|
||||
|
|
||||
if (type.Name.EndsWith(interfaceName)) |
|
||||
{ |
|
||||
serviceTypes.Add(interfaceType); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return serviceTypes; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,19 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Reflection; |
||||
|
|
||||
|
namespace Volo.Abp.DependencyInjection |
||||
|
{ |
||||
|
public static class ExposedServiceExplorer |
||||
|
{ |
||||
|
public static List<Type> GetExposedServices(Type type) |
||||
|
{ |
||||
|
return type |
||||
|
.GetCustomAttributes() |
||||
|
.OfType<IExposedServiceTypesProvider>() |
||||
|
.SelectMany(p => p.GetExposedServiceTypes(type)) |
||||
|
.ToList(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue