|
|
|
@ -28,14 +28,22 @@ public static class ServiceCollectionHttpClientProxyExtensions |
|
|
|
/// The name of the remote service configuration to be used by the Static HTTP Client proxies.
|
|
|
|
/// See <see cref="AbpRemoteServiceOptions"/>.
|
|
|
|
/// </param>
|
|
|
|
/// <param name="applicationServiceTypes">
|
|
|
|
/// Can be set to filter the application service types to be registered.
|
|
|
|
/// Default value: All.
|
|
|
|
/// </param>
|
|
|
|
public static IServiceCollection AddStaticHttpClientProxies( |
|
|
|
[NotNull] this IServiceCollection services, |
|
|
|
[NotNull] Assembly assembly, |
|
|
|
[NotNull] string remoteServiceConfigurationName = RemoteServiceConfigurationDictionary.DefaultName) |
|
|
|
[NotNull] string remoteServiceConfigurationName = RemoteServiceConfigurationDictionary.DefaultName, |
|
|
|
ApplicationServiceTypes applicationServiceTypes = ApplicationServiceTypes.All) |
|
|
|
{ |
|
|
|
Check.NotNull(services, nameof(assembly)); |
|
|
|
|
|
|
|
var serviceTypes = assembly.GetTypes().Where(IsSuitableForClientProxying).ToArray(); |
|
|
|
var serviceTypes = assembly |
|
|
|
.GetTypes() |
|
|
|
.Where(x => IsSuitableForClientProxying(x, applicationServiceTypes)) |
|
|
|
.ToArray(); |
|
|
|
|
|
|
|
foreach (var serviceType in serviceTypes) |
|
|
|
{ |
|
|
|
@ -64,15 +72,23 @@ public static class ServiceCollectionHttpClientProxyExtensions |
|
|
|
/// <param name="asDefaultServices">
|
|
|
|
/// True, to register the HTTP client proxy as the default implementation for the services.
|
|
|
|
/// </param>
|
|
|
|
/// <param name="applicationServiceTypes">
|
|
|
|
/// Can be set to filter the application service types to be registered.
|
|
|
|
/// Default value: All.
|
|
|
|
/// </param>
|
|
|
|
public static IServiceCollection AddHttpClientProxies( |
|
|
|
[NotNull] this IServiceCollection services, |
|
|
|
[NotNull] Assembly assembly, |
|
|
|
[NotNull] string remoteServiceConfigurationName = RemoteServiceConfigurationDictionary.DefaultName, |
|
|
|
bool asDefaultServices = true) |
|
|
|
bool asDefaultServices = true, |
|
|
|
ApplicationServiceTypes applicationServiceTypes = ApplicationServiceTypes.All) |
|
|
|
{ |
|
|
|
Check.NotNull(services, nameof(assembly)); |
|
|
|
|
|
|
|
var serviceTypes = assembly.GetTypes().Where(IsSuitableForClientProxying).ToArray(); |
|
|
|
var serviceTypes = assembly |
|
|
|
.GetTypes() |
|
|
|
.Where(x => IsSuitableForClientProxying(x, applicationServiceTypes)) |
|
|
|
.ToArray(); |
|
|
|
|
|
|
|
foreach (var serviceType in serviceTypes) |
|
|
|
{ |
|
|
|
@ -228,13 +244,28 @@ public static class ServiceCollectionHttpClientProxyExtensions |
|
|
|
/// </summary>
|
|
|
|
/// <param name="type">Type to check</param>
|
|
|
|
/// <returns>True, if the type is suitable for proxying. Otherwise false.</returns>
|
|
|
|
private static bool IsSuitableForClientProxying(Type type) |
|
|
|
private static bool IsSuitableForClientProxying( |
|
|
|
Type type, |
|
|
|
ApplicationServiceTypes applicationServiceTypes) |
|
|
|
{ |
|
|
|
//TODO: Add option to change type filter
|
|
|
|
if (!type.IsInterface || |
|
|
|
!type.IsPublic || |
|
|
|
type.IsGenericType || |
|
|
|
!typeof(IRemoteService).IsAssignableFrom(type)) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (applicationServiceTypes == ApplicationServiceTypes.ApplicationServices) |
|
|
|
{ |
|
|
|
return !type.IsDefined(typeof(IntegrationServiceAttribute)); |
|
|
|
} |
|
|
|
|
|
|
|
if (applicationServiceTypes == ApplicationServiceTypes.IntegrationServices) |
|
|
|
{ |
|
|
|
return type.IsDefined(typeof(IntegrationServiceAttribute)); |
|
|
|
} |
|
|
|
|
|
|
|
return type.IsInterface |
|
|
|
&& type.IsPublic |
|
|
|
&& !type.IsGenericType |
|
|
|
&& typeof(IRemoteService).IsAssignableFrom(type); |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|