Browse Source

fix(dapr): example Remove redundant remote service configuration options

pull/445/head
cKey 4 years ago
parent
commit
549b32a08f
  1. 7
      aspnet-core/LINGYUN.MicroService.Common.sln
  2. 3
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore.Wrapper/FodyWeavers.xml
  3. 30
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore.Wrapper/FodyWeavers.xsd
  4. 16
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore.Wrapper/LINGYUN.Abp.Dapr.Actors.AspNetCore.Wrapper.csproj
  5. 20
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore.Wrapper/LINGYUN/Abp/Dapr/Actors/AspNetCore/Wrapper/AbpDaprActorsAspNetCoreWrapperModule.cs
  6. 4
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN.Abp.Dapr.Actors.AspNetCore.csproj
  7. 9
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN/Abp/Dapr/Actors/AspNetCore/AbpDaprActorsAspNetCoreModule.cs
  8. 1
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprActorsModule.cs
  9. 14
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprRemoteServiceOptions.cs
  10. 15
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DynamicProxying/DynamicDaprActorProxyInterceptor.cs
  11. 2
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientModule.cs
  12. 12
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprRemoteServiceOptions.cs
  13. 30
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DaprRemoteServiceConfiguration.cs
  14. 32
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DaprRemoteServiceConfigurationDictionary.cs
  15. 25
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DaprRemoteServiceConfigurationExtensions.cs
  16. 10
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DaprApiDescriptionFinder.cs
  17. 7
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DynamicDaprClientProxyInterceptor.cs
  18. 15
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DynamicDaprProxyInterceptorClientProxy.cs
  19. 11
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicDaprClientProxyExtensions.cs

7
aspnet-core/LINGYUN.MicroService.Common.sln

@ -230,6 +230,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "hangfire", "hangfire", "{3A
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Hangfire.Dashboard", "modules\common\LINGYUN.Abp.Hangfire.Dashboard\LINGYUN.Abp.Hangfire.Dashboard.csproj", "{FF518E10-C9AB-440C-8E8D-9CFF67A926AC}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Hangfire.Dashboard", "modules\common\LINGYUN.Abp.Hangfire.Dashboard\LINGYUN.Abp.Hangfire.Dashboard.csproj", "{FF518E10-C9AB-440C-8E8D-9CFF67A926AC}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Dapr.Actors.AspNetCore.Wrapper", "modules\dapr\LINGYUN.Abp.Dapr.Actors.AspNetCore.Wrapper\LINGYUN.Abp.Dapr.Actors.AspNetCore.Wrapper.csproj", "{49E0B90B-8635-43D0-B0AB-9D484CAE68B5}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -592,6 +594,10 @@ Global
{FF518E10-C9AB-440C-8E8D-9CFF67A926AC}.Debug|Any CPU.Build.0 = Debug|Any CPU {FF518E10-C9AB-440C-8E8D-9CFF67A926AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF518E10-C9AB-440C-8E8D-9CFF67A926AC}.Release|Any CPU.ActiveCfg = Release|Any CPU {FF518E10-C9AB-440C-8E8D-9CFF67A926AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF518E10-C9AB-440C-8E8D-9CFF67A926AC}.Release|Any CPU.Build.0 = Release|Any CPU {FF518E10-C9AB-440C-8E8D-9CFF67A926AC}.Release|Any CPU.Build.0 = Release|Any CPU
{49E0B90B-8635-43D0-B0AB-9D484CAE68B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{49E0B90B-8635-43D0-B0AB-9D484CAE68B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{49E0B90B-8635-43D0-B0AB-9D484CAE68B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{49E0B90B-8635-43D0-B0AB-9D484CAE68B5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -706,6 +712,7 @@ Global
{E31F0421-3DFD-4225-A96B-38D603FB504D} = {38E21687-5F19-42C9-9D11-4B1D2EF64EDB} {E31F0421-3DFD-4225-A96B-38D603FB504D} = {38E21687-5F19-42C9-9D11-4B1D2EF64EDB}
{AC5F30A4-284E-4C57-A2E6-B1AD0D5AF7C9} = {38E21687-5F19-42C9-9D11-4B1D2EF64EDB} {AC5F30A4-284E-4C57-A2E6-B1AD0D5AF7C9} = {38E21687-5F19-42C9-9D11-4B1D2EF64EDB}
{FF518E10-C9AB-440C-8E8D-9CFF67A926AC} = {3A0784A6-AFBF-406F-B79E-9505EB100445} {FF518E10-C9AB-440C-8E8D-9CFF67A926AC} = {3A0784A6-AFBF-406F-B79E-9505EB100445}
{49E0B90B-8635-43D0-B0AB-9D484CAE68B5} = {7FDFB22F-1BFF-4E05-9427-78B7A8461D50}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {06C707C6-02C0-411A-AD3B-2D0E13787CB8} SolutionGuid = {06C707C6-02C0-411A-AD3B-2D0E13787CB8}

3
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore.Wrapper/FodyWeavers.xml

@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ConfigureAwait ContinueOnCapturedContext="false" />
</Weavers>

30
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore.Wrapper/FodyWeavers.xsd

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" />
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>

16
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore.Wrapper/LINGYUN.Abp.Dapr.Actors.AspNetCore.Wrapper.csproj

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\configureawait.props" />
<Import Project="..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\common\LINGYUN.Abp.Wrapper\LINGYUN.Abp.Wrapper.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.Dapr.Actors.AspNetCore\LINGYUN.Abp.Dapr.Actors.AspNetCore.csproj" />
</ItemGroup>
</Project>

20
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore.Wrapper/LINGYUN/Abp/Dapr/Actors/AspNetCore/Wrapper/AbpDaprActorsAspNetCoreWrapperModule.cs

@ -0,0 +1,20 @@
using Dapr.Actors;
using LINGYUN.Abp.Wrapper;
using Volo.Abp.Modularity;
namespace LINGYUN.Abp.Dapr.Actors.AspNetCore.Wrapper
{
[DependsOn(
typeof(AbpDaprActorsAspNetCoreModule),
typeof(AbpWrapperModule))]
public class AbpDaprActorsAspNetCoreWrapperModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpWrapperOptions>(options =>
{
options.IgnoredInterfaces.TryAdd<IActor>();
});
}
}
}

4
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN.Abp.Dapr.Actors.AspNetCore.csproj

@ -13,8 +13,4 @@
<PackageReference Include="Volo.Abp.AspNetCore" Version="$(VoloAbpPackageVersion)" /> <PackageReference Include="Volo.Abp.AspNetCore" Version="$(VoloAbpPackageVersion)" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\common\LINGYUN.Abp.Wrapper\LINGYUN.Abp.Wrapper.csproj" />
</ItemGroup>
</Project> </Project>

9
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN/Abp/Dapr/Actors/AspNetCore/AbpDaprActorsAspNetCoreModule.cs

@ -1,6 +1,5 @@
using Dapr.Actors; using Dapr.Actors;
using Dapr.Actors.Runtime; using Dapr.Actors.Runtime;
using LINGYUN.Abp.Wrapper;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@ -12,8 +11,7 @@ using Volo.Abp.Modularity;
namespace LINGYUN.Abp.Dapr.Actors.AspNetCore namespace LINGYUN.Abp.Dapr.Actors.AspNetCore
{ {
[DependsOn( [DependsOn(
typeof(AbpAspNetCoreModule), typeof(AbpAspNetCoreModule))]
typeof(AbpWrapperModule))]
public class AbpDaprActorsAspNetCoreModule : AbpModule public class AbpDaprActorsAspNetCoreModule : AbpModule
{ {
public override void PreConfigureServices(ServiceConfigurationContext context) public override void PreConfigureServices(ServiceConfigurationContext context)
@ -30,11 +28,6 @@ namespace LINGYUN.Abp.Dapr.Actors.AspNetCore
endpointContext.Endpoints.MapActorsHandlers(); endpointContext.Endpoints.MapActorsHandlers();
}); });
}); });
Configure<AbpWrapperOptions>(options =>
{
options.IgnoredInterfaces.TryAdd<IActor>();
});
} }
private static void AddDefinitionActor(IServiceCollection services) private static void AddDefinitionActor(IServiceCollection services)

1
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprActorsModule.cs

@ -17,7 +17,6 @@ namespace LINGYUN.Abp.Dapr.Actors
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {
var configuration = context.Services.GetConfiguration(); var configuration = context.Services.GetConfiguration();
Configure<AbpDaprRemoteServiceOptions>(configuration);
context.Services.AddHttpClient(DaprHttpClient); context.Services.AddHttpClient(DaprHttpClient);
} }
} }

14
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprRemoteServiceOptions.cs

@ -1,14 +0,0 @@
using Volo.Abp.Http.Client;
namespace LINGYUN.Abp.Dapr.Actors
{
public class AbpDaprRemoteServiceOptions
{
public RemoteServiceConfigurationDictionary RemoteServices { get; set; }
public AbpDaprRemoteServiceOptions()
{
RemoteServices = new RemoteServiceConfigurationDictionary();
}
}
}

15
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/DynamicProxying/DynamicDaprActorProxyInterceptor.cs

@ -13,6 +13,7 @@ using Volo.Abp;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.DynamicProxy; using Volo.Abp.DynamicProxy;
using Volo.Abp.Http; using Volo.Abp.Http;
using Volo.Abp.Http.Client;
using Volo.Abp.Http.Client.Authentication; using Volo.Abp.Http.Client.Authentication;
using Volo.Abp.Http.Client.Proxying; using Volo.Abp.Http.Client.Proxying;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
@ -24,25 +25,25 @@ namespace LINGYUN.Abp.Dapr.Actors.DynamicProxying
where TService: IActor where TService: IActor
{ {
protected ICurrentTenant CurrentTenant { get; } protected ICurrentTenant CurrentTenant { get; }
protected AbpDaprRemoteServiceOptions DaprServiceOptions { get; }
protected AbpDaprActorProxyOptions DaprActorProxyOptions { get; } protected AbpDaprActorProxyOptions DaprActorProxyOptions { get; }
protected IProxyHttpClientFactory HttpClientFactory { get; } protected IProxyHttpClientFactory HttpClientFactory { get; }
protected IRemoteServiceHttpClientAuthenticator ClientAuthenticator { get; } protected IRemoteServiceHttpClientAuthenticator ClientAuthenticator { get; }
protected IRemoteServiceConfigurationProvider RemoteServiceConfigurationProvider { get; }
public ILogger<DynamicDaprActorProxyInterceptor<TService>> Logger { get; set; } public ILogger<DynamicDaprActorProxyInterceptor<TService>> Logger { get; set; }
public DynamicDaprActorProxyInterceptor( public DynamicDaprActorProxyInterceptor(
IOptions<AbpDaprActorProxyOptions> daprActorProxyOptions, IOptions<AbpDaprActorProxyOptions> daprActorProxyOptions,
IOptionsSnapshot<AbpDaprRemoteServiceOptions> daprActorOptions,
IProxyHttpClientFactory httpClientFactory, IProxyHttpClientFactory httpClientFactory,
IRemoteServiceHttpClientAuthenticator clientAuthenticator, IRemoteServiceHttpClientAuthenticator clientAuthenticator,
IRemoteServiceConfigurationProvider remoteServiceConfigurationProvider,
ICurrentTenant currentTenant) ICurrentTenant currentTenant)
{ {
CurrentTenant = currentTenant; CurrentTenant = currentTenant;
HttpClientFactory = httpClientFactory; HttpClientFactory = httpClientFactory;
ClientAuthenticator = clientAuthenticator; ClientAuthenticator = clientAuthenticator;
DaprActorProxyOptions = daprActorProxyOptions.Value; DaprActorProxyOptions = daprActorProxyOptions.Value;
DaprServiceOptions = daprActorOptions.Value; RemoteServiceConfigurationProvider = remoteServiceConfigurationProvider;
Logger = NullLogger<DynamicDaprActorProxyInterceptor<TService>>.Instance; Logger = NullLogger<DynamicDaprActorProxyInterceptor<TService>>.Instance;
} }
@ -68,7 +69,7 @@ namespace LINGYUN.Abp.Dapr.Actors.DynamicProxying
{ {
// 获取Actor配置 // 获取Actor配置
var actorProxyConfig = DaprActorProxyOptions.ActorProxies.GetOrDefault(typeof(TService)) ?? throw new AbpException($"Could not get DynamicDaprActorProxyConfig for {typeof(TService).FullName}."); var actorProxyConfig = DaprActorProxyOptions.ActorProxies.GetOrDefault(typeof(TService)) ?? throw new AbpException($"Could not get DynamicDaprActorProxyConfig for {typeof(TService).FullName}.");
var remoteServiceConfig = DaprServiceOptions.RemoteServices.GetConfigurationOrDefault(actorProxyConfig.RemoteServiceName); var remoteServiceConfig = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync(actorProxyConfig.RemoteServiceName);
// Actors的定义太多, 可以考虑使用默认的 BaseUrl 作为远程地址 // Actors的定义太多, 可以考虑使用默认的 BaseUrl 作为远程地址
if (remoteServiceConfig.BaseUrl.IsNullOrWhiteSpace()) if (remoteServiceConfig.BaseUrl.IsNullOrWhiteSpace())

2
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientModule.cs

@ -17,8 +17,6 @@ namespace LINGYUN.Abp.Dapr.Client
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {
var configuration = context.Services.GetConfiguration();
Configure<AbpDaprRemoteServiceOptions>(configuration);
context.Services.AddHttpClient(DaprHttpClient); context.Services.AddHttpClient(DaprHttpClient);
context.Services.AddTransient(typeof(DynamicDaprProxyInterceptorClientProxy<>)); context.Services.AddTransient(typeof(DynamicDaprProxyInterceptorClientProxy<>));

12
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprRemoteServiceOptions.cs

@ -1,12 +0,0 @@
namespace LINGYUN.Abp.Dapr.Client
{
public class AbpDaprRemoteServiceOptions
{
public DaprRemoteServiceConfigurationDictionary RemoteServices { get; set; }
public AbpDaprRemoteServiceOptions()
{
RemoteServices = new DaprRemoteServiceConfigurationDictionary();
}
}
}

30
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DaprRemoteServiceConfiguration.cs

@ -1,30 +0,0 @@
using System.Collections.Generic;
using Volo.Abp.Http.Client;
namespace LINGYUN.Abp.Dapr.Client
{
public class DaprRemoteServiceConfiguration : RemoteServiceConfiguration
{
/// <summary>
/// Base AppId.
/// </summary>
public string AppId
{
get => this.GetOrDefault(nameof(AppId));
set => this[nameof(AppId)] = value;
}
public DaprRemoteServiceConfiguration()
{
}
public DaprRemoteServiceConfiguration(
string appId,
string baseUil,
string version)
: base(baseUil, version)
{
this[nameof(AppId)] = appId;
}
}
}

32
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DaprRemoteServiceConfigurationDictionary.cs

@ -1,32 +0,0 @@
using JetBrains.Annotations;
using System.Collections.Generic;
using Volo.Abp;
namespace LINGYUN.Abp.Dapr.Client
{
public class DaprRemoteServiceConfigurationDictionary : Dictionary<string, DaprRemoteServiceConfiguration>
{
public const string DefaultName = "Default";
public DaprRemoteServiceConfiguration Default
{
get => this.GetOrDefault(DefaultName);
set => this[DefaultName] = value;
}
[NotNull]
public DaprRemoteServiceConfiguration GetConfigurationOrDefault(string name)
{
return this.GetOrDefault(name)
?? Default
?? throw new AbpException($"Dapr remote service '{name}' was not found and there is no default configuration.");
}
[CanBeNull]
public DaprRemoteServiceConfiguration GetConfigurationOrDefaultOrNull(string name)
{
return this.GetOrDefault(name)
?? Default;
}
}
}

25
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DaprRemoteServiceConfigurationExtensions.cs

@ -0,0 +1,25 @@
using JetBrains.Annotations;
using System.Collections.Generic;
using Volo.Abp;
using Volo.Abp.Http.Client;
namespace LINGYUN.Abp.Dapr.Client;
public static class DaprRemoteServiceConfigurationExtensions
{
public const string AppId = "AppId";
[NotNull]
public static string GetAppId([NotNull] this RemoteServiceConfiguration configuration)
{
Check.NotNullOrEmpty(configuration, nameof(configuration));
return configuration.GetOrDefault(AppId) ?? throw new AbpException($"Could not get AppId for RemoteServices Configuration.");
}
public static RemoteServiceConfiguration SetAppId([NotNull] this RemoteServiceConfiguration configuration, [CanBeNull] string value)
{
configuration[AppId] = value;
return configuration;
}
}

10
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DaprApiDescriptionFinder.cs

@ -22,6 +22,11 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
{ {
public class DaprApiDescriptionFinder : IDaprApiDescriptionFinder, ITransientDependency public class DaprApiDescriptionFinder : IDaprApiDescriptionFinder, ITransientDependency
{ {
public static JsonSerializerOptions DeserializeOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
public ICancellationTokenProvider CancellationTokenProvider { get; set; } public ICancellationTokenProvider CancellationTokenProvider { get; set; }
protected IApiDescriptionCache Cache { get; } protected IApiDescriptionCache Cache { get; }
protected AbpCorrelationIdOptions AbpCorrelationIdOptions { get; } protected AbpCorrelationIdOptions AbpCorrelationIdOptions { get; }
@ -112,10 +117,7 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
var content = await response.Content.ReadAsStringAsync(); var content = await response.Content.ReadAsStringAsync();
var result = JsonSerializer.Deserialize<ApplicationApiDescriptionModel>(content, new JsonSerializerOptions var result = JsonSerializer.Deserialize<ApplicationApiDescriptionModel>(content, DeserializeOptions);
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
});
return result; return result;
} }

7
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DynamicDaprClientProxyInterceptor.cs

@ -29,7 +29,6 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
public ILogger<DynamicDaprClientProxyInterceptor<TService>> Logger { get; set; } public ILogger<DynamicDaprClientProxyInterceptor<TService>> Logger { get; set; }
protected DynamicDaprProxyInterceptorClientProxy<TService> InterceptorClientProxy { get; } protected DynamicDaprProxyInterceptorClientProxy<TService> InterceptorClientProxy { get; }
protected AbpDaprRemoteServiceOptions AbpRemoteServiceOptions { get; }
protected AbpDaprClientProxyOptions ClientProxyOptions { get; } protected AbpDaprClientProxyOptions ClientProxyOptions { get; }
protected IRemoteServiceConfigurationProvider RemoteServiceConfigurationProvider { get; } protected IRemoteServiceConfigurationProvider RemoteServiceConfigurationProvider { get; }
protected IDaprApiDescriptionFinder ApiDescriptionFinder { get; } protected IDaprApiDescriptionFinder ApiDescriptionFinder { get; }
@ -37,7 +36,6 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
public DynamicDaprClientProxyInterceptor( public DynamicDaprClientProxyInterceptor(
DynamicDaprProxyInterceptorClientProxy<TService> interceptorClientProxy, DynamicDaprProxyInterceptorClientProxy<TService> interceptorClientProxy,
IOptions<AbpDaprClientProxyOptions> clientProxyOptions, IOptions<AbpDaprClientProxyOptions> clientProxyOptions,
IOptions<AbpDaprRemoteServiceOptions> remoteServiceOptions,
IRemoteServiceConfigurationProvider remoteServiceConfigurationProvider, IRemoteServiceConfigurationProvider remoteServiceConfigurationProvider,
IDaprApiDescriptionFinder apiDescriptionFinder) IDaprApiDescriptionFinder apiDescriptionFinder)
{ {
@ -45,7 +43,6 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
RemoteServiceConfigurationProvider = remoteServiceConfigurationProvider; RemoteServiceConfigurationProvider = remoteServiceConfigurationProvider;
ApiDescriptionFinder = apiDescriptionFinder; ApiDescriptionFinder = apiDescriptionFinder;
ClientProxyOptions = clientProxyOptions.Value; ClientProxyOptions = clientProxyOptions.Value;
AbpRemoteServiceOptions = remoteServiceOptions.Value;
Logger = NullLogger<DynamicDaprClientProxyInterceptor<TService>>.Instance; Logger = NullLogger<DynamicDaprClientProxyInterceptor<TService>>.Instance;
} }
@ -76,11 +73,11 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
{ {
var clientConfig = ClientProxyOptions.DaprClientProxies.GetOrDefault(typeof(TService)) ?? var clientConfig = ClientProxyOptions.DaprClientProxies.GetOrDefault(typeof(TService)) ??
throw new AbpException($"Could not get DynamicDaprClientProxyConfig for {typeof(TService).FullName}."); throw new AbpException($"Could not get DynamicDaprClientProxyConfig for {typeof(TService).FullName}.");
var remoteServiceConfig = AbpRemoteServiceOptions.RemoteServices.GetConfigurationOrDefault(clientConfig.RemoteServiceName); var remoteServiceConfig = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync(clientConfig.RemoteServiceName);
return await ApiDescriptionFinder.FindActionAsync( return await ApiDescriptionFinder.FindActionAsync(
clientConfig.RemoteServiceName, clientConfig.RemoteServiceName,
remoteServiceConfig.AppId, remoteServiceConfig.GetAppId(),
typeof(TService), typeof(TService),
invocation.Method invocation.Method
); );

15
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DynamicDaprProxyInterceptorClientProxy.cs

@ -13,7 +13,6 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
{ {
public class DynamicDaprProxyInterceptorClientProxy<TService> : ClientProxyBase<TService> public class DynamicDaprProxyInterceptorClientProxy<TService> : ClientProxyBase<TService>
{ {
protected IOptions<AbpDaprRemoteServiceOptions> DaprRemoteServiceOptions => LazyServiceProvider.LazyGetRequiredService<IOptions<AbpDaprRemoteServiceOptions>>();
protected IOptions<AbpDaprClientProxyOptions> DaprClientProxyOptions => LazyServiceProvider.LazyGetRequiredService<IOptions<AbpDaprClientProxyOptions>>(); protected IOptions<AbpDaprClientProxyOptions> DaprClientProxyOptions => LazyServiceProvider.LazyGetRequiredService<IOptions<AbpDaprClientProxyOptions>>();
protected IDaprClientFactory DaprClientFactory => LazyServiceProvider.LazyGetRequiredService<IDaprClientFactory>(); protected IDaprClientFactory DaprClientFactory => LazyServiceProvider.LazyGetRequiredService<IDaprClientFactory>();
@ -64,28 +63,28 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
return JsonSerializer.Deserialize<T>(stringContent); return JsonSerializer.Deserialize<T>(stringContent);
} }
protected override Task<string> GetConfiguredApiVersionAsync(ClientProxyRequestContext requestContext) protected override async Task<string> GetConfiguredApiVersionAsync(ClientProxyRequestContext requestContext)
{ {
var clientConfig = DaprClientProxyOptions.Value.DaprClientProxies.GetOrDefault(requestContext.ServiceType) var clientConfig = DaprClientProxyOptions.Value.DaprClientProxies.GetOrDefault(requestContext.ServiceType)
?? throw new AbpException($"Could not get DynamicDaprClientProxyConfig for {requestContext.ServiceType.FullName}."); ?? throw new AbpException($"Could not get DynamicDaprClientProxyConfig for {requestContext.ServiceType.FullName}.");
var remoteServiceConfig = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync(clientConfig.RemoteServiceName);
var remoteServiceConfig = DaprRemoteServiceOptions.Value.RemoteServices.GetConfigurationOrDefaultOrNull(clientConfig.RemoteServiceName); return remoteServiceConfig?.Version;
return Task.FromResult(remoteServiceConfig?.Version);
} }
private async Task<HttpResponseMessage> MakeRequestAsync(ClientProxyRequestContext requestContext) private async Task<HttpResponseMessage> MakeRequestAsync(ClientProxyRequestContext requestContext)
{ {
var clientConfig = DaprClientProxyOptions.Value.DaprClientProxies.GetOrDefault(requestContext.ServiceType) ?? throw new AbpException($"Could not get DaprClientProxyConfig for {requestContext.ServiceType.FullName}."); var clientConfig = DaprClientProxyOptions.Value.DaprClientProxies.GetOrDefault(requestContext.ServiceType) ?? throw new AbpException($"Could not get DaprClientProxyConfig for {requestContext.ServiceType.FullName}.");
var remoteServiceConfig = DaprRemoteServiceOptions.Value.RemoteServices.GetConfigurationOrDefault(clientConfig.RemoteServiceName); var remoteServiceConfig = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync(clientConfig.RemoteServiceName);
var appId = remoteServiceConfig.GetAppId();
var apiVersion = await GetApiVersionInfoAsync(requestContext); var apiVersion = await GetApiVersionInfoAsync(requestContext);
var methodName = await GetUrlWithParametersAsync(requestContext, apiVersion); var methodName = await GetUrlWithParametersAsync(requestContext, apiVersion);
// See: https://docs.dapr.io/reference/api/service_invocation_api/#examples // See: https://docs.dapr.io/reference/api/service_invocation_api/#examples
var daprClient = DaprClientFactory.CreateClient(clientConfig.RemoteServiceName); var daprClient = DaprClientFactory.CreateClient(clientConfig.RemoteServiceName);
var requestMessage = daprClient.CreateInvokeMethodRequest( var requestMessage = daprClient.CreateInvokeMethodRequest(
requestContext.Action.GetHttpMethod(), requestContext.Action.GetHttpMethod(),
remoteServiceConfig.AppId, appId,
methodName); methodName);
requestMessage.Content = await ClientProxyRequestPayloadBuilder.BuildContentAsync( requestMessage.Content = await ClientProxyRequestPayloadBuilder.BuildContentAsync(
requestContext.Action, requestContext.Action,
@ -119,7 +118,7 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
// 增加一个可配置的请求消息 // 增加一个可配置的请求消息
foreach (var clientRequestAction in DaprClientProxyOptions.Value.ProxyRequestActions) foreach (var clientRequestAction in DaprClientProxyOptions.Value.ProxyRequestActions)
{ {
clientRequestAction(remoteServiceConfig.AppId, requestMessage); clientRequestAction(appId, requestMessage);
} }
var response = await daprClient.InvokeMethodWithResponseAsync(requestMessage, GetCancellationToken(requestContext.Arguments)); var response = await daprClient.InvokeMethodWithResponseAsync(requestMessage, GetCancellationToken(requestContext.Arguments));

11
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicDaprClientProxyExtensions.cs

@ -9,6 +9,7 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Castle.DynamicProxy; using Volo.Abp.Castle.DynamicProxy;
using Volo.Abp.Http.Client;
using Volo.Abp.Json.SystemTextJson; using Volo.Abp.Json.SystemTextJson;
using Volo.Abp.Validation; using Volo.Abp.Validation;
@ -23,7 +24,7 @@ namespace Microsoft.Extensions.DependencyInjection
public static IServiceCollection AddDaprClientProxies( public static IServiceCollection AddDaprClientProxies(
[NotNull] this IServiceCollection services, [NotNull] this IServiceCollection services,
[NotNull] Assembly assembly, [NotNull] Assembly assembly,
[NotNull] string remoteServiceConfigurationName = DaprRemoteServiceConfigurationDictionary.DefaultName, [NotNull] string remoteServiceConfigurationName = RemoteServiceConfigurationDictionary.DefaultName,
bool asDefaultServices = true) bool asDefaultServices = true)
{ {
Check.NotNull(services, nameof(assembly)); Check.NotNull(services, nameof(assembly));
@ -44,7 +45,7 @@ namespace Microsoft.Extensions.DependencyInjection
public static IServiceCollection AddDaprClientProxy<T>( public static IServiceCollection AddDaprClientProxy<T>(
[NotNull] this IServiceCollection services, [NotNull] this IServiceCollection services,
[NotNull] string remoteServiceConfigurationName = DaprRemoteServiceConfigurationDictionary.DefaultName, [NotNull] string remoteServiceConfigurationName = RemoteServiceConfigurationDictionary.DefaultName,
bool asDefaultService = true) bool asDefaultService = true)
{ {
return services.AddDaprClientProxy( return services.AddDaprClientProxy(
@ -57,7 +58,7 @@ namespace Microsoft.Extensions.DependencyInjection
public static IServiceCollection AddDaprClientProxy( public static IServiceCollection AddDaprClientProxy(
[NotNull] this IServiceCollection services, [NotNull] this IServiceCollection services,
[NotNull] Type type, [NotNull] Type type,
[NotNull] string remoteServiceConfigurationName = DaprRemoteServiceConfigurationDictionary.DefaultName, [NotNull] string remoteServiceConfigurationName = RemoteServiceConfigurationDictionary.DefaultName,
bool asDefaultService = true) bool asDefaultService = true)
{ {
Check.NotNull(services, nameof(services)); Check.NotNull(services, nameof(services));
@ -114,7 +115,7 @@ namespace Microsoft.Extensions.DependencyInjection
private static IServiceCollection AddDaprClientFactory( private static IServiceCollection AddDaprClientFactory(
[NotNull] this IServiceCollection services, [NotNull] this IServiceCollection services,
[NotNull] string remoteServiceConfigurationName = DaprRemoteServiceConfigurationDictionary.DefaultName) [NotNull] string remoteServiceConfigurationName = RemoteServiceConfigurationDictionary.DefaultName)
{ {
var preOptions = services.ExecutePreConfiguredActions<AbpDaprClientBuilderOptions>(); var preOptions = services.ExecutePreConfiguredActions<AbpDaprClientBuilderOptions>();
@ -129,7 +130,7 @@ namespace Microsoft.Extensions.DependencyInjection
var jsonOptions = provider.GetRequiredService<IOptions<AbpSystemTextJsonSerializerOptions>>().Value; var jsonOptions = provider.GetRequiredService<IOptions<AbpSystemTextJsonSerializerOptions>>().Value;
builder.UseJsonSerializationOptions(jsonOptions.JsonSerializerOptions); builder.UseJsonSerializationOptions(jsonOptions.JsonSerializerOptions);
var options = provider.GetRequiredService<IOptions<AbpDaprRemoteServiceOptions>>().Value; var options = provider.GetRequiredService<IOptions<AbpRemoteServiceOptions>>().Value;
builder.UseHttpEndpoint( builder.UseHttpEndpoint(
options.RemoteServices options.RemoteServices
.GetConfigurationOrDefault(remoteServiceConfigurationName).BaseUrl); .GetConfigurationOrDefault(remoteServiceConfigurationName).BaseUrl);

Loading…
Cancel
Save