From 590d2960ea58b9304ca956c6b43b66610705c0e2 Mon Sep 17 00:00:00 2001 From: Necati Meral Date: Sun, 14 Jun 2020 20:39:53 +0200 Subject: [PATCH 1/2] 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); + } } } From 39770a90f78f4ca9df75e9b3bc7e17d2f671e5ce Mon Sep 17 00:00:00 2001 From: Necati Meral Date: Mon, 15 Jun 2020 08:47:46 +0200 Subject: [PATCH 2/2] Update framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Halil İbrahim Kalkan --- .../ServiceCollectionDynamicHttpClientProxyExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3a2432a737..e20b60bf54 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 @@ -201,7 +201,7 @@ namespace Microsoft.Extensions.DependencyInjection return type.IsInterface && type.IsPublic - && type.IsGenericType + && !type.IsGenericType && typeof(IRemoteService).IsAssignableFrom(type); } }