pull/3348/head
maliming 5 years ago
parent 651ca79ce0
commit 1475940d85

@ -40,9 +40,9 @@ namespace Volo.Abp.AspNetCore.Mvc
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
DynamicProxyIgnoreTypes.IgnoreTypes.AddIfNotContains(typeof(ControllerBase));
DynamicProxyIgnoreTypes.IgnoreTypes.AddIfNotContains(typeof(PageModel));
DynamicProxyIgnoreTypes.IgnoreTypes.AddIfNotContains(typeof(ViewComponent));
DynamicProxyIgnoreTypes.Add<ControllerBase>();
DynamicProxyIgnoreTypes.Add<PageModel>();
DynamicProxyIgnoreTypes.Add<ViewComponent>();
context.Services.AddConventionalRegistrar(new AbpAspNetCoreMvcConventionalRegistrar());
}

@ -9,7 +9,7 @@ namespace Volo.Abp.Auditing
{
public static void RegisterIfNeeded(IOnServiceRegistredContext context)
{
if (ShouldIntercept(context.ImplementationType) && !DynamicProxyIgnoreTypes.Contains(context.ImplementationType))
if (ShouldIntercept(context.ImplementationType))
{
context.Interceptors.TryAdd<AuditingInterceptor>();
}
@ -17,6 +17,11 @@ namespace Volo.Abp.Auditing
private static bool ShouldIntercept(Type type)
{
if (DynamicProxyIgnoreTypes.Contains(type))
{
return false;
}
if (ShouldAuditTypeByDefault(type))
{
return true;

@ -11,7 +11,7 @@ namespace Volo.Abp.Authorization
{
public static void RegisterIfNeeded(IOnServiceRegistredContext context)
{
if (ShouldIntercept(context.ImplementationType) && !DynamicProxyIgnoreTypes.Contains(context.ImplementationType))
if (ShouldIntercept(context.ImplementationType))
{
context.Interceptors.TryAdd<AuthorizationInterceptor>();
}
@ -19,8 +19,8 @@ namespace Volo.Abp.Authorization
private static bool ShouldIntercept(Type type)
{
return type.IsDefined(typeof(AuthorizeAttribute), true) ||
AnyMethodHasAuthorizeAttribute(type);
return !DynamicProxyIgnoreTypes.Contains(type) &&
(type.IsDefined(typeof(AuthorizeAttribute), true) || AnyMethodHasAuthorizeAttribute(type));
}
private static bool AnyMethodHasAuthorizeAttribute(Type implementationType)

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Volo.Abp.Threading;
namespace Volo.Abp.DynamicProxy
{
@ -14,11 +15,16 @@ namespace Volo.Abp.DynamicProxy
/// </summary>
public static class DynamicProxyIgnoreTypes
{
public static List<Type> IgnoreTypes { get; } = new List<Type>();
private static HashSet<Type> IgnoredTypes { get; } = new HashSet<Type>();
public static void Add<T>()
{
IgnoredTypes.Locking(() => IgnoredTypes.AddIfNotContains(typeof(T)));
}
public static bool Contains(Type type, bool includeDerivedTypes = true)
{
return includeDerivedTypes ? IgnoreTypes.Any(t => t.IsAssignableFrom(type)) : IgnoreTypes.Contains(type);
return includeDerivedTypes ? IgnoredTypes.Any(t => t.IsAssignableFrom(type)) : IgnoredTypes.Contains(type);
}
}
}

@ -10,7 +10,7 @@ namespace Volo.Abp.Features
{
public static void RegisterIfNeeded(IOnServiceRegistredContext context)
{
if (ShouldIntercept(context.ImplementationType) && !DynamicProxyIgnoreTypes.Contains(context.ImplementationType))
if (ShouldIntercept(context.ImplementationType))
{
context.Interceptors.TryAdd<FeatureInterceptor>();
}
@ -18,8 +18,9 @@ namespace Volo.Abp.Features
private static bool ShouldIntercept(Type type)
{
return type.IsDefined(typeof(RequiresFeatureAttribute), true) ||
AnyMethodHasRequiresFeatureAttribute(type);
return !DynamicProxyIgnoreTypes.Contains(type) &&
(type.IsDefined(typeof(RequiresFeatureAttribute), true) ||
AnyMethodHasRequiresFeatureAttribute(type));
}
private static bool AnyMethodHasRequiresFeatureAttribute(Type implementationType)

@ -1,4 +1,5 @@
using System.Reflection;
using System;
using System.Reflection;
using Volo.Abp.DependencyInjection;
using Volo.Abp.DynamicProxy;
@ -8,10 +9,15 @@ namespace Volo.Abp.Uow
{
public static void RegisterIfNeeded(IOnServiceRegistredContext context)
{
if (UnitOfWorkHelper.IsUnitOfWorkType(context.ImplementationType.GetTypeInfo()) && !DynamicProxyIgnoreTypes.Contains(context.ImplementationType))
if (ShouldIntercept(context.ImplementationType))
{
context.Interceptors.TryAdd<UnitOfWorkInterceptor>();
}
}
private static bool ShouldIntercept(Type type)
{
return !DynamicProxyIgnoreTypes.Contains(type) && UnitOfWorkHelper.IsUnitOfWorkType(type.GetTypeInfo());
}
}
}

@ -1,4 +1,5 @@
using Volo.Abp.DependencyInjection;
using System;
using Volo.Abp.DependencyInjection;
using Volo.Abp.DynamicProxy;
namespace Volo.Abp.Validation
@ -7,10 +8,15 @@ namespace Volo.Abp.Validation
{
public static void RegisterIfNeeded(IOnServiceRegistredContext context)
{
if (typeof(IValidationEnabled).IsAssignableFrom(context.ImplementationType) && !DynamicProxyIgnoreTypes.Contains(context.ImplementationType))
if (ShouldIntercept(context.ImplementationType))
{
context.Interceptors.TryAdd<ValidationInterceptor>();
}
}
private static bool ShouldIntercept(Type type)
{
return !DynamicProxyIgnoreTypes.Contains(type) && typeof(IValidationEnabled).IsAssignableFrom(type);
}
}
}
Loading…
Cancel
Save