Browse Source

Added `IsSuitableForDynamicClientProxying` and added generic interface check

pull/4345/head
Necati Meral 6 years ago
parent
commit
590d2960ea
  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