Browse Source

Fix ExposedServiceExplorer.

pull/1156/head
Halil ibrahim Kalkan 7 years ago
parent
commit
fe5199cd43
  1. 36
      framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/ExposeServicesAttribute.cs
  2. 7
      framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/ExposedServiceExplorer.cs
  3. 4
      framework/test/Volo.Abp.Core.Tests/Volo/Abp/DependencyInjection/AutoRegistrationHelper_Tests.cs

36
framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/ExposeServicesAttribute.cs

@ -7,29 +7,45 @@ namespace Volo.Abp.DependencyInjection
{
public class ExposeServicesAttribute : Attribute, IExposedServiceTypesProvider
{
public Type[] ExposedServiceTypes { get; }
public ExposeServicesAttribute(params Type[] exposedServiceTypes)
public Type[] ServiceTypes { get; }
public bool? IncludeDefaults { get; set; }
public bool? IncludeSelf { get; set; }
public ExposeServicesAttribute(params Type[] serviceTypes)
{
ExposedServiceTypes = exposedServiceTypes ?? new Type[0];
ServiceTypes = serviceTypes ?? new Type[0];
}
public Type[] GetExposedServiceTypes(Type targetType)
{
if (ExposedServiceTypes.Any())
var serviceList = ServiceTypes.ToList();
if (IncludeDefaults == true)
{
foreach (var type in GetDefaultServices(targetType))
{
serviceList.AddIfNotContains(type);
}
if (IncludeSelf != false)
{
serviceList.AddIfNotContains(targetType);
}
}
else if (IncludeSelf == true)
{
return ExposedServiceTypes;
serviceList.AddIfNotContains(targetType);
}
return GetDefaultExposedServices(targetType).ToArray();
return serviceList.ToArray();
}
private static List<Type> GetDefaultExposedServices(Type type)
private static List<Type> GetDefaultServices(Type type)
{
var serviceTypes = new List<Type>();
serviceTypes.Add(type);
foreach (var interfaceType in type.GetTypeInfo().GetInterfaces())
{
var interfaceName = interfaceType.Name;

7
framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/ExposedServiceExplorer.cs

@ -7,11 +7,18 @@ namespace Volo.Abp.DependencyInjection
{
public static class ExposedServiceExplorer
{
private static readonly ExposeServicesAttribute DefaultExposeServicesAttribute =
new ExposeServicesAttribute
{
IncludeDefaults = true
};
public static List<Type> GetExposedServices(Type type)
{
return type
.GetCustomAttributes()
.OfType<IExposedServiceTypesProvider>()
.DefaultIfEmpty(DefaultExposeServicesAttribute)
.SelectMany(p => p.GetExposedServiceTypes(type))
.ToList();
}

4
framework/test/Volo.Abp.Core.Tests/Volo/Abp/DependencyInjection/AutoRegistrationHelper_Tests.cs

@ -1,6 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using System.Linq;
using Shouldly;
using Xunit;
namespace Volo.Abp.DependencyInjection

Loading…
Cancel
Save