Add ApplicationServiceTypes to ConventionalControllerSetting.

pull/14051/head
Halil İbrahim Kalkan 3 years ago
parent ac0e488ecb
commit 9d5d27a860

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using Volo.Abp.Application.Services;
using Volo.Abp.Reflection;
namespace Volo.Abp.AspNetCore.Mvc.Conventions;
@ -48,6 +49,11 @@ public class ConventionalControllerSetting
[CanBeNull]
public Func<Type, bool> TypePredicate { get; set; }
/// <summary>
/// Default value: All.
/// </summary>
public ApplicationServiceTypes ApplicationServiceTypes { get; set; } = ApplicationServiceTypes.All;
[CanBeNull]
public Action<ControllerModel> ControllerModelConfigurer { get; set; }
@ -78,6 +84,7 @@ public class ConventionalControllerSetting
{
var types = Assembly.GetTypes()
.Where(IsRemoteService)
.Where(IsPreferredApplicationServiceType)
.WhereIf(TypePredicate != null, TypePredicate);
foreach (var type in types)
@ -85,7 +92,7 @@ public class ConventionalControllerSetting
ControllerTypes.Add(type);
}
}
public IReadOnlyList<Type> GetControllerTypes()
{
return ControllerTypes.ToImmutableList();
@ -111,4 +118,24 @@ public class ConventionalControllerSetting
return false;
}
}
private bool IsPreferredApplicationServiceType(Type type)
{
if (ApplicationServiceTypes == ApplicationServiceTypes.All)
{
return true;
}
if (ApplicationServiceTypes == ApplicationServiceTypes.ApplicationServices)
{
return !type.IsDefined(typeof(IntegrationServiceAttribute));
}
if (ApplicationServiceTypes == ApplicationServiceTypes.IntegrationServices)
{
return type.IsDefined(typeof(IntegrationServiceAttribute));
}
return true;
}
}

@ -0,0 +1,22 @@
using System;
namespace Volo.Abp.Application.Services;
[Flags]
public enum ApplicationServiceTypes : byte
{
/// <summary>
/// Only application services without <see cref="IntegrationServiceAttribute"/>.
/// </summary>
ApplicationServices = 1,
/// <summary>
/// Application services with <see cref="IntegrationServiceAttribute"/>.
/// </summary>
IntegrationServices = 2,
/// <summary>
/// All application services.
/// </summary>
All = ApplicationServices | IntegrationServices
}
Loading…
Cancel
Save