From 590d2960ea58b9304ca956c6b43b66610705c0e2 Mon Sep 17 00:00:00 2001 From: Necati Meral Date: Sun, 14 Jun 2020 20:39:53 +0200 Subject: [PATCH] Added `IsSuitableForDynamicClientProxying` and added generic interface check --- ...lectionDynamicHttpClientProxyExtensions.cs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs b/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs index e3fd273026..3a2432a737 100644 --- a/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs +++ b/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; } + + /// + /// Checks wether the type is suitable to use with the dynamic proxying. + /// Currently the type is checked statically against some fixed conditions. + /// + /// Type to check + /// True, if the type is suitable for dynamic proxying. Otherwise false. + static bool IsSuitableForDynamicClientProxying(Type type) + { + //TODO: Add option to change type filter + + return type.IsInterface + && type.IsPublic + && type.IsGenericType + && typeof(IRemoteService).IsAssignableFrom(type); + } } }