Browse Source

Merge pull request #4345 from NecatiMeral/ignore-generic-interfaces-for-proxying

Added `IsSuitableForDynamicClientProxying` and added generic interface restriction
pull/4363/head
Halil İbrahim Kalkan 6 years ago
committed by GitHub
parent
commit
e7baff9d55
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs

23
framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs

@ -45,11 +45,8 @@ namespace Microsoft.Extensions.DependencyInjection
AddHttpClientFactoryAndPolicy(services, remoteServiceConfigurationName, configureHttpClientBuilder);
//TODO: Make a configuration option and add remoteServiceName inside it!
//TODO: Add option to change type filter
var serviceTypes = assembly.GetTypes().Where(t =>
t.IsInterface && t.IsPublic && typeof(IRemoteService).IsAssignableFrom(t)
);
var serviceTypes = assembly.GetTypes().Where(IsSuitableForDynamicClientProxying);
foreach (var serviceType in serviceTypes)
{
@ -155,7 +152,7 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddTransient(interceptorType);
var interceptorAdapterType = typeof(AbpAsyncDeterminationInterceptor<>).MakeGenericType(interceptorType);
var validationInterceptorAdapterType =
typeof(AbpAsyncDeterminationInterceptor<>).MakeGenericType(typeof(ValidationInterceptor));
@ -191,5 +188,21 @@ namespace Microsoft.Extensions.DependencyInjection
return services;
}
/// <summary>
/// Checks wether the type is suitable to use with the dynamic proxying.
/// Currently the type is checked statically against some fixed conditions.
/// </summary>
/// <param name="type">Type to check</param>
/// <returns>True, if the type is suitable for dynamic proxying. Otherwise false.</returns>
static bool IsSuitableForDynamicClientProxying(Type type)
{
//TODO: Add option to change type filter
return type.IsInterface
&& type.IsPublic
&& !type.IsGenericType
&& typeof(IRemoteService).IsAssignableFrom(type);
}
}
}

Loading…
Cancel
Save