From 0abd02d1625d3acd650b36dfa509534b4d93d87c Mon Sep 17 00:00:00 2001
From: cKey <35512826+colinin@users.noreply.github.com>
Date: Sun, 28 Nov 2021 11:40:40 +0800
Subject: [PATCH] =?UTF-8?q?feat(wrapper):=20=E5=A2=9E=E5=8A=A0=E5=AF=B9?=
=?UTF-8?q?=E4=BA=8Edapr=E7=9A=84=E5=8C=85=E8=A3=85=E7=BB=93=E6=9E=9C?=
=?UTF-8?q?=E5=A4=84=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
aspnet-core/LINGYUN.MicroService.Common.sln | 9 +-
.../LINGYUN.Abp.HttpClient.Wrapper.csproj | 18 +
.../Wrapper/AbpHttpClientWrapperModule.cs | 13 +
...amicHttpProxyInterceptorWrapClientProxy.cs | 153 ++++
.../LINGYUN/Abp}/Wrapper/AbpHttpWrapConsts.cs | 2 +-
.../LINGYUN/Abp/Wrapper/AbpWrapperOptions.cs | 69 ++
.../LINGYUN.Abp.Dapr.Actors.AspNetCore.csproj | 4 +
.../AbpDaprActorsAspNetCoreModule.cs | 115 +--
.../Abp/Dapr/Actors/AbpDaprActorsModule.cs | 48 +-
.../LINGYUN.Abp.Dapr.Client.csproj | 1 +
.../Abp/Dapr/Client/AbpDaprClientModule.cs | 6 +-
.../DynamicDaprClientProxyInterceptor.cs | 654 +++++++++---------
.../Wrapper/AbpAspNetCoreMvcWrapperModule.cs | 2 +-
.../Wrapper/AbpAspNetCoreMvcWrapperOptions.cs | 70 --
.../AbpExceptionPageWrapResultFilter.cs | 4 +-
.../AbpExceptionWrapResultFilter.cs | 4 +-
.../Wrapper/Filters/AbpWrapResultFilter.cs | 1 +
.../Mvc/Wrapper/WrapResultChecker.cs | 6 +-
.../Wraping/EmptyActionResultWrapper.cs | 2 +-
.../Wraping/JsonActionResultWrapper.cs | 4 +-
.../Wraping/ObjectActionResultWrapper.cs | 12 +-
.../Mvc/AbpAspNetCoreMvcTestModule.cs | 3 +-
.../Mvc/Results/WrapResultController_Tests.cs | 2 +-
...INGYUN.Abp.Dapr.AspNetCore.TestHost.csproj | 2 +
.../Dapr/AbpDaprAspNetCoreTestHostModule.cs | 90 +--
.../Dapr/ServiceInvocation/TestAppService.cs | 94 +--
.../Dapr/Client/Tests/TestAppServiceTests.cs | 74 +-
.../LINGYUN/Abp/Dapr/AbpDaprTestModule.cs | 23 +-
.../Dapr/ServiceInvocation/ITestAppService.cs | 30 +-
.../LINGYUN/Abp/Dapr/TestNeedWrapObject.cs | 7 +
30 files changed, 900 insertions(+), 622 deletions(-)
create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.HttpClient.Wrapper/LINGYUN.Abp.HttpClient.Wrapper.csproj
create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.HttpClient.Wrapper/LINGYUN/Abp/HttpClient/Wrapper/AbpHttpClientWrapperModule.cs
create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.HttpClient.Wrapper/LINGYUN/Abp/HttpClient/Wrapper/DynamicHttpProxyInterceptorWrapClientProxy.cs
rename aspnet-core/modules/{mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc => common/LINGYUN.Abp.Wrapper/LINGYUN/Abp}/Wrapper/AbpHttpWrapConsts.cs (68%)
delete mode 100644 aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/AbpAspNetCoreMvcWrapperOptions.cs
create mode 100644 aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/TestNeedWrapObject.cs
diff --git a/aspnet-core/LINGYUN.MicroService.Common.sln b/aspnet-core/LINGYUN.MicroService.Common.sln
index 4466df56e..f40b45866 100644
--- a/aspnet-core/LINGYUN.MicroService.Common.sln
+++ b/aspnet-core/LINGYUN.MicroService.Common.sln
@@ -204,7 +204,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.AspNetCore.Test
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.AspNetCore.Mvc.Tests", "tests\LINGYUN.Abp.AspNetCore.Mvc.Tests\LINGYUN.Abp.AspNetCore.Mvc.Tests.csproj", "{AE5E6DE8-FC02-4633-BA49-C4B8ABADB502}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Wrapper.Tests", "tests\LINGYUN.Abp.Wrapper.Tests\LINGYUN.Abp.Wrapper.Tests.csproj", "{31AED9ED-29BD-4F2F-8D3A-F00CBB9FC73C}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Wrapper.Tests", "tests\LINGYUN.Abp.Wrapper.Tests\LINGYUN.Abp.Wrapper.Tests.csproj", "{31AED9ED-29BD-4F2F-8D3A-F00CBB9FC73C}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.HttpClient.Wrapper", "modules\common\LINGYUN.Abp.HttpClient.Wrapper\LINGYUN.Abp.HttpClient.Wrapper.csproj", "{F6CABEE7-DE34-458A-8787-95DFB1DA4762}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -536,6 +538,10 @@ Global
{31AED9ED-29BD-4F2F-8D3A-F00CBB9FC73C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{31AED9ED-29BD-4F2F-8D3A-F00CBB9FC73C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{31AED9ED-29BD-4F2F-8D3A-F00CBB9FC73C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F6CABEE7-DE34-458A-8787-95DFB1DA4762}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F6CABEE7-DE34-458A-8787-95DFB1DA4762}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F6CABEE7-DE34-458A-8787-95DFB1DA4762}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F6CABEE7-DE34-458A-8787-95DFB1DA4762}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -639,6 +645,7 @@ Global
{BD4165DB-F8A4-4715-A05A-CC08F6A18D67} = {B86C21A4-73B7-471E-B73A-B4B905EC9435}
{AE5E6DE8-FC02-4633-BA49-C4B8ABADB502} = {B86C21A4-73B7-471E-B73A-B4B905EC9435}
{31AED9ED-29BD-4F2F-8D3A-F00CBB9FC73C} = {B86C21A4-73B7-471E-B73A-B4B905EC9435}
+ {F6CABEE7-DE34-458A-8787-95DFB1DA4762} = {086BE5BE-8594-4DA7-8819-935FEF76DABD}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {06C707C6-02C0-411A-AD3B-2D0E13787CB8}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.HttpClient.Wrapper/LINGYUN.Abp.HttpClient.Wrapper.csproj b/aspnet-core/modules/common/LINGYUN.Abp.HttpClient.Wrapper/LINGYUN.Abp.HttpClient.Wrapper.csproj
new file mode 100644
index 000000000..cd4d8ad0e
--- /dev/null
+++ b/aspnet-core/modules/common/LINGYUN.Abp.HttpClient.Wrapper/LINGYUN.Abp.HttpClient.Wrapper.csproj
@@ -0,0 +1,18 @@
+
+
+
+
+
+ net5.0
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.HttpClient.Wrapper/LINGYUN/Abp/HttpClient/Wrapper/AbpHttpClientWrapperModule.cs b/aspnet-core/modules/common/LINGYUN.Abp.HttpClient.Wrapper/LINGYUN/Abp/HttpClient/Wrapper/AbpHttpClientWrapperModule.cs
new file mode 100644
index 000000000..9f7aa9db9
--- /dev/null
+++ b/aspnet-core/modules/common/LINGYUN.Abp.HttpClient.Wrapper/LINGYUN/Abp/HttpClient/Wrapper/AbpHttpClientWrapperModule.cs
@@ -0,0 +1,13 @@
+using LINGYUN.Abp.Wrapper;
+using Volo.Abp.Http.Client;
+using Volo.Abp.Modularity;
+
+namespace LINGYUN.Abp.HttpClient.Wrapper
+{
+ [DependsOn(
+ typeof(AbpHttpClientModule),
+ typeof(AbpWrapperModule))]
+ public class AbpHttpClientWrapperModule : AbpModule
+ {
+ }
+}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.HttpClient.Wrapper/LINGYUN/Abp/HttpClient/Wrapper/DynamicHttpProxyInterceptorWrapClientProxy.cs b/aspnet-core/modules/common/LINGYUN.Abp.HttpClient.Wrapper/LINGYUN/Abp/HttpClient/Wrapper/DynamicHttpProxyInterceptorWrapClientProxy.cs
new file mode 100644
index 000000000..b568c0da6
--- /dev/null
+++ b/aspnet-core/modules/common/LINGYUN.Abp.HttpClient.Wrapper/LINGYUN/Abp/HttpClient/Wrapper/DynamicHttpProxyInterceptorWrapClientProxy.cs
@@ -0,0 +1,153 @@
+using LINGYUN.Abp.Wrapper;
+using Microsoft.Extensions.Options;
+using System;
+using System.Collections.Generic;
+using System.Net.Http;
+using System.Threading.Tasks;
+using Volo.Abp;
+using Volo.Abp.Content;
+using Volo.Abp.DependencyInjection;
+using Volo.Abp.Http;
+using Volo.Abp.Http.Client;
+using Volo.Abp.Http.Client.Authentication;
+using Volo.Abp.Http.Client.ClientProxying;
+using Volo.Abp.Http.Client.DynamicProxying;
+
+namespace LINGYUN.Abp.HttpClient.Wrapper
+{
+ [Dependency(ReplaceServices = true)]
+ [ExposeServices(typeof(DynamicHttpProxyInterceptorClientProxy<>))]
+ public class DynamicHttpProxyInterceptorWrapClientProxy
+ : DynamicHttpProxyInterceptorClientProxy, ITransientDependency
+ {
+ protected IOptions WrapperOptions => LazyServiceProvider.LazyGetRequiredService>();
+
+ protected override async Task RequestAsync(ClientProxyRequestContext requestContext)
+ {
+ var response = await RequestAndGetResponseAsync(requestContext);
+
+ var responseContent = response.Content;
+
+ if (typeof(T) == typeof(IRemoteStreamContent) ||
+ typeof(T) == typeof(RemoteStreamContent))
+ {
+ /* returning a class that holds a reference to response
+ * content just to be sure that GC does not dispose of
+ * it before we finish doing our work with the stream */
+ return (T)(object)new RemoteStreamContent(
+ await responseContent.ReadAsStreamAsync(),
+ responseContent.Headers?.ContentDisposition?.FileNameStar ??
+ RemoveQuotes(responseContent.Headers?.ContentDisposition?.FileName).ToString(),
+ responseContent.Headers?.ContentType?.ToString(),
+ responseContent.Headers?.ContentLength);
+ }
+
+ var stringContent = await responseContent.ReadAsStringAsync();
+
+ if (stringContent.IsNullOrWhiteSpace())
+ {
+ return default;
+ }
+
+ // 对于包装后的结果需要处理
+ if (response.Headers.Contains(AbpHttpWrapConsts.AbpWrapResult))
+ {
+ var wrapResult = JsonSerializer.Deserialize>(stringContent);
+
+ ThrowExceptionForResponse(wrapResult);
+
+ if (typeof(T) == typeof(string))
+ {
+ return (T)(object)wrapResult.Result;
+ }
+
+ return wrapResult.Result;
+ }
+
+ if (typeof(T) == typeof(string))
+ {
+ return (T)(object)stringContent;
+ }
+
+ if (stringContent.IsNullOrWhiteSpace())
+ {
+ return default;
+ }
+
+ return JsonSerializer.Deserialize(stringContent);
+ }
+
+ public override async Task CallRequestAsync(ClientProxyRequestContext requestContext)
+ {
+ var response = await RequestAndGetResponseAsync(requestContext);
+ // 对于包装后的结果需要处理
+ if (response.Headers.Contains(AbpHttpWrapConsts.AbpWrapResult))
+ {
+ var stringContent = await response.Content.ReadAsStringAsync();
+ var wrapResult = JsonSerializer.Deserialize(stringContent);
+
+ ThrowExceptionForResponse(wrapResult);
+ }
+
+ return response.Content;
+ }
+
+ protected virtual void ThrowExceptionForResponse(WrapResult wrapResult)
+ {
+ if (!string.Equals(wrapResult.Code, WrapperOptions.Value.CodeWithSuccess))
+ {
+ var errorInfo = new RemoteServiceErrorInfo(
+ wrapResult.Message,
+ wrapResult.Details,
+ wrapResult.Code);
+ throw new AbpRemoteCallException(errorInfo)
+ {
+ HttpStatusCode = (int)WrapperOptions.Value.HttpStatusCode
+ };
+ }
+ }
+
+ protected virtual async Task RequestAndGetResponseAsync(ClientProxyRequestContext requestContext)
+ {
+ var clientConfig = ClientOptions.Value.HttpClientProxies.GetOrDefault(requestContext.ServiceType) ?? throw new AbpException($"Could not get HttpClientProxyConfig for {requestContext.ServiceType.FullName}.");
+ var remoteServiceConfig = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync(clientConfig.RemoteServiceName);
+
+ var client = HttpClientFactory.Create(clientConfig.RemoteServiceName);
+
+ var apiVersion = await GetApiVersionInfoAsync(requestContext);
+ var url = remoteServiceConfig.BaseUrl.EnsureEndsWith('/') + await GetUrlWithParametersAsync(requestContext, apiVersion);
+
+ var requestMessage = new HttpRequestMessage(requestContext.Action.GetHttpMethod(), url)
+ {
+ Content = await ClientProxyRequestPayloadBuilder.BuildContentAsync(requestContext.Action, requestContext.Arguments, JsonSerializer, apiVersion)
+ };
+
+ AddHeaders(requestContext.Arguments, requestContext.Action, requestMessage, apiVersion);
+
+ if (requestContext.Action.AllowAnonymous != true)
+ {
+ await ClientAuthenticator.Authenticate(
+ new RemoteServiceHttpClientAuthenticateContext(
+ client,
+ requestMessage,
+ remoteServiceConfig,
+ clientConfig.RemoteServiceName
+ )
+ );
+ }
+
+ var response = await client.SendAsync(
+ requestMessage,
+ HttpCompletionOption.ResponseHeadersRead /*this will buffer only the headers, the content will be used as a stream*/,
+ GetCancellationToken(requestContext.Arguments)
+ );
+
+ if (!response.IsSuccessStatusCode)
+ {
+ await ThrowExceptionForResponseAsync(response);
+ }
+
+ return response;
+ }
+ }
+}
diff --git a/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/AbpHttpWrapConsts.cs b/aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/AbpHttpWrapConsts.cs
similarity index 68%
rename from aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/AbpHttpWrapConsts.cs
rename to aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/AbpHttpWrapConsts.cs
index c3b8e6955..bd0f708b9 100644
--- a/aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/AbpHttpWrapConsts.cs
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/AbpHttpWrapConsts.cs
@@ -1,4 +1,4 @@
-namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper
+namespace LINGYUN.Abp.Wrapper
{
public static class AbpHttpWrapConsts
{
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/AbpWrapperOptions.cs b/aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/AbpWrapperOptions.cs
index 9f9f1d971..8d674bceb 100644
--- a/aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/AbpWrapperOptions.cs
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/AbpWrapperOptions.cs
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
+using System.Net;
+using Volo.Abp.Collections;
namespace LINGYUN.Abp.Wrapper
{
@@ -10,12 +12,79 @@ namespace LINGYUN.Abp.Wrapper
/// 默认: 500
///
public string CodeWithUnhandled { get; set; }
+ ///
+ /// 是否启用包装器
+ ///
+ public bool IsEnabled { get; set; }
+ ///
+ /// 成功时返回代码
+ /// 默认:0
+ ///
+ public string CodeWithSuccess { get; set; }
+ ///
+ /// 资源为空时是否提示错误
+ /// 默认: false
+ ///
+ public bool ErrorWithEmptyResult { get; set; }
+ ///
+ /// 资源为空时返回代码
+ /// 默认:404
+ ///
+ public Func CodeWithEmptyResult { get; set; }
+ ///
+ /// 资源为空时返回错误消息
+ ///
+ public Func MessageWithEmptyResult { get; set; }
+ ///
+ /// 包装后的返回状态码
+ /// 默认:200 HttpStatusCode.OK
+ ///
+ public HttpStatusCode HttpStatusCode { get; set; }
+ ///
+ /// 忽略Url开头类型
+ ///
+ public IList IgnorePrefixUrls { get; }
+ ///
+ /// 忽略指定命名空间
+ ///
+ public IList IgnoreNamespaces { get; }
+ ///
+ /// 忽略控制器
+ ///
+ public ITypeList IgnoreControllers { get; }
+ ///
+ /// 忽略返回值
+ ///
+ public ITypeList IgnoreReturnTypes { get; }
+ ///
+ /// 忽略异常
+ ///
+ public ITypeList IgnoreExceptions { get; }
+ ///
+ /// 忽略服务类型
+ ///
+ public ITypeList IgnoreBaseTypes { get; }
internal IDictionary ExceptionHandles { get; }
public AbpWrapperOptions()
{
CodeWithUnhandled = "500";
+ CodeWithSuccess = "0";
+ HttpStatusCode = HttpStatusCode.OK;
+ ErrorWithEmptyResult = false;
+
+ IgnorePrefixUrls = new List();
+ IgnoreNamespaces = new List();
+
+ IgnoreControllers = new TypeList();
+ IgnoreReturnTypes = new TypeList();
+ IgnoreBaseTypes = new TypeList();
+ IgnoreExceptions = new TypeList();
+
+ CodeWithEmptyResult = (_) => "404";
+ MessageWithEmptyResult = (_) => "Not Found";
+
ExceptionHandles = new Dictionary();
}
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN.Abp.Dapr.Actors.AspNetCore.csproj b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN.Abp.Dapr.Actors.AspNetCore.csproj
index 1fee35da8..359dc88a4 100644
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN.Abp.Dapr.Actors.AspNetCore.csproj
+++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN.Abp.Dapr.Actors.AspNetCore.csproj
@@ -12,4 +12,8 @@
+
+
+
+
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN/Abp/Dapr/Actors/AspNetCore/AbpDaprActorsAspNetCoreModule.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN/Abp/Dapr/Actors/AspNetCore/AbpDaprActorsAspNetCoreModule.cs
index fa267ada0..771e6becc 100644
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN/Abp/Dapr/Actors/AspNetCore/AbpDaprActorsAspNetCoreModule.cs
+++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN/Abp/Dapr/Actors/AspNetCore/AbpDaprActorsAspNetCoreModule.cs
@@ -1,54 +1,61 @@
-using Dapr.Actors;
-using Dapr.Actors.Runtime;
-using Microsoft.AspNetCore.Builder;
-using Microsoft.AspNetCore.Routing;
-using Microsoft.Extensions.DependencyInjection;
-using System;
-using System.Collections.Generic;
-using Volo.Abp.AspNetCore;
-using Volo.Abp.Modularity;
-
-namespace LINGYUN.Abp.Dapr.Actors.AspNetCore
-{
- [DependsOn(
- typeof(AbpAspNetCoreModule))]
- public class AbpDaprActorsAspNetCoreModule : AbpModule
- {
- public override void PreConfigureServices(ServiceConfigurationContext context)
- {
- AddDefinitionActor(context.Services);
- }
-
- public override void ConfigureServices(ServiceConfigurationContext context)
- {
- Configure(options =>
- {
- options.EndpointConfigureActions.Add(endpointContext =>
- {
- endpointContext.Endpoints.MapActorsHandlers();
- });
- });
- }
-
- private static void AddDefinitionActor(IServiceCollection services)
- {
- var actorRegistrations = new List();
-
- services.OnRegistred(context =>
- {
- if (typeof(IActor).IsAssignableFrom(context.ImplementationType) &&
- !actorRegistrations.Contains(context.ImplementationType))
- {
- var actorRegistration = new ActorRegistration(context.ImplementationType.GetActorTypeInfo());
-
- actorRegistrations.Add(actorRegistration);
- }
- });
-
- services.AddActors(options =>
- {
- options.Actors.AddIfNotContains(actorRegistrations);
- });
- }
- }
-}
+using Dapr.Actors;
+using Dapr.Actors.Runtime;
+using LINGYUN.Abp.Wrapper;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Routing;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using Volo.Abp.AspNetCore;
+using Volo.Abp.Modularity;
+
+namespace LINGYUN.Abp.Dapr.Actors.AspNetCore
+{
+ [DependsOn(
+ typeof(AbpAspNetCoreModule),
+ typeof(AbpWrapperModule))]
+ public class AbpDaprActorsAspNetCoreModule : AbpModule
+ {
+ public override void PreConfigureServices(ServiceConfigurationContext context)
+ {
+ AddDefinitionActor(context.Services);
+ }
+
+ public override void ConfigureServices(ServiceConfigurationContext context)
+ {
+ Configure(options =>
+ {
+ options.EndpointConfigureActions.Add(endpointContext =>
+ {
+ endpointContext.Endpoints.MapActorsHandlers();
+ });
+ });
+
+ Configure(options =>
+ {
+ options.IgnoreBaseTypes.TryAdd();
+ });
+ }
+
+ private static void AddDefinitionActor(IServiceCollection services)
+ {
+ var actorRegistrations = new List();
+
+ services.OnRegistred(context =>
+ {
+ if (typeof(IActor).IsAssignableFrom(context.ImplementationType) &&
+ !actorRegistrations.Contains(context.ImplementationType))
+ {
+ var actorRegistration = new ActorRegistration(context.ImplementationType.GetActorTypeInfo());
+
+ actorRegistrations.Add(actorRegistration);
+ }
+ });
+
+ services.AddActors(options =>
+ {
+ options.Actors.AddIfNotContains(actorRegistrations);
+ });
+ }
+ }
+}
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprActorsModule.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprActorsModule.cs
index 903968a6f..9a777a844 100644
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprActorsModule.cs
+++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors/LINGYUN/Abp/Dapr/Actors/AbpDaprActorsModule.cs
@@ -1,24 +1,24 @@
-using Microsoft.Extensions.DependencyInjection;
-using Volo.Abp.Http.Client;
-using Volo.Abp.Modularity;
-
-namespace LINGYUN.Abp.Dapr.Actors
-{
- [DependsOn(
- typeof(AbpHttpClientModule)
- )]
- public class AbpDaprActorsModule : AbpModule
- {
- ///
- /// 与AbpHttpClient集成,创建一个命名HttpClient
- ///
- internal const string DaprHttpClient = "_AbpDaprActorsClient";
-
- public override void ConfigureServices(ServiceConfigurationContext context)
- {
- var configuration = context.Services.GetConfiguration();
- Configure(configuration);
- context.Services.AddHttpClient(DaprHttpClient);
- }
- }
-}
+using Microsoft.Extensions.DependencyInjection;
+using Volo.Abp.Http.Client;
+using Volo.Abp.Modularity;
+
+namespace LINGYUN.Abp.Dapr.Actors
+{
+ [DependsOn(
+ typeof(AbpHttpClientModule)
+ )]
+ public class AbpDaprActorsModule : AbpModule
+ {
+ ///
+ /// 与AbpHttpClient集成,创建一个命名HttpClient
+ ///
+ internal const string DaprHttpClient = "_AbpDaprActorsClient";
+
+ public override void ConfigureServices(ServiceConfigurationContext context)
+ {
+ var configuration = context.Services.GetConfiguration();
+ Configure(configuration);
+ context.Services.AddHttpClient(DaprHttpClient);
+ }
+ }
+}
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN.Abp.Dapr.Client.csproj b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN.Abp.Dapr.Client.csproj
index 71c93a355..0a755bd21 100644
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN.Abp.Dapr.Client.csproj
+++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN.Abp.Dapr.Client.csproj
@@ -12,6 +12,7 @@
+
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientModule.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientModule.cs
index 34d9adb97..b5714474d 100644
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientModule.cs
+++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientModule.cs
@@ -1,11 +1,13 @@
-using Microsoft.Extensions.DependencyInjection;
+using LINGYUN.Abp.Wrapper;
+using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Http.Client;
using Volo.Abp.Modularity;
namespace LINGYUN.Abp.Dapr.Client
{
[DependsOn(
- typeof(AbpHttpClientModule)
+ typeof(AbpHttpClientModule),
+ typeof(AbpWrapperModule)
)]
public class AbpDaprClientModule : AbpModule
{
diff --git a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DynamicDaprClientProxyInterceptor.cs b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DynamicDaprClientProxyInterceptor.cs
index d9f9adf3f..b7c24c5fe 100644
--- a/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DynamicDaprClientProxyInterceptor.cs
+++ b/aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DynamicDaprClientProxyInterceptor.cs
@@ -1,312 +1,342 @@
-using Dapr.Client;
-using Microsoft.Extensions.Logging;
-using Microsoft.Extensions.Logging.Abstractions;
-using Microsoft.Extensions.Options;
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
-using System.Net.Http;
-using System.Net.Http.Headers;
-using System.Reflection;
-using System.Threading;
-using System.Threading.Tasks;
-using Volo.Abp;
-using Volo.Abp.Content;
-using Volo.Abp.DependencyInjection;
-using Volo.Abp.DynamicProxy;
-using Volo.Abp.Http;
-using Volo.Abp.Http.Client;
-using Volo.Abp.Http.Client.Authentication;
-using Volo.Abp.Http.Client.DynamicProxying;
-using Volo.Abp.Http.Modeling;
-using Volo.Abp.Http.ProxyScripting.Generators;
-using Volo.Abp.Json;
-using Volo.Abp.MultiTenancy;
-using Volo.Abp.Threading;
-using Volo.Abp.Tracing;
-
-namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
-{
- public class DynamicDaprClientProxyInterceptor : AbpInterceptor, ITransientDependency
- {
- protected static MethodInfo MakeRequestAndGetResultAsyncMethod { get; }
-
- protected IDaprClientFactory DaprClientFactory { get; }
- protected ICancellationTokenProvider CancellationTokenProvider { get; }
- protected ICorrelationIdProvider CorrelationIdProvider { get; }
- protected ICurrentTenant CurrentTenant { get; }
- protected AbpCorrelationIdOptions AbpCorrelationIdOptions { get; }
- protected IDynamicProxyHttpClientFactory HttpClientFactory { get; }
- protected IDaprApiDescriptionFinder ApiDescriptionFinder { get; }
- protected AbpDaprRemoteServiceOptions AbpRemoteServiceOptions { get; }
- protected AbpDaprClientProxyOptions ClientProxyOptions { get; }
- protected IJsonSerializer JsonSerializer { get; }
- protected IRemoteServiceHttpClientAuthenticator ClientAuthenticator { get; }
-
- public ILogger> Logger { get; set; }
-
- static DynamicDaprClientProxyInterceptor()
- {
- MakeRequestAndGetResultAsyncMethod = typeof(DynamicDaprClientProxyInterceptor)
- .GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
- .First(m => m.Name == nameof(MakeRequestAndGetResultAsync) && m.IsGenericMethodDefinition);
- }
-
- public DynamicDaprClientProxyInterceptor(
- IDaprClientFactory daprClientFactory,
- IOptions clientProxyOptions,
- IOptionsSnapshot remoteServiceOptions,
- IDaprApiDescriptionFinder apiDescriptionFinder,
- IJsonSerializer jsonSerializer,
- IDynamicProxyHttpClientFactory dynamicProxyHttpClientFactory,
- IRemoteServiceHttpClientAuthenticator clientAuthenticator,
- ICancellationTokenProvider cancellationTokenProvider,
- ICorrelationIdProvider correlationIdProvider,
- IOptions correlationIdOptions,
- ICurrentTenant currentTenant)
- {
- DaprClientFactory = daprClientFactory;
- CancellationTokenProvider = cancellationTokenProvider;
- CorrelationIdProvider = correlationIdProvider;
- CurrentTenant = currentTenant;
- HttpClientFactory = dynamicProxyHttpClientFactory;
- AbpCorrelationIdOptions = correlationIdOptions.Value;
- ApiDescriptionFinder = apiDescriptionFinder;
- JsonSerializer = jsonSerializer;
- ClientAuthenticator = clientAuthenticator;
- ClientProxyOptions = clientProxyOptions.Value;
- AbpRemoteServiceOptions = remoteServiceOptions.Value;
-
- Logger = NullLogger>.Instance;
- }
-
- public override async Task InterceptAsync(IAbpMethodInvocation invocation)
- {
- if (invocation.Method.ReturnType.GenericTypeArguments.IsNullOrEmpty())
- {
- await MakeRequestAsync(invocation);
- }
- else
- {
- var result = (Task)MakeRequestAndGetResultAsyncMethod
- .MakeGenericMethod(invocation.Method.ReturnType.GenericTypeArguments[0])
- .Invoke(this, new object[] { invocation });
-
- invocation.ReturnValue = await GetResultAsync(
- result,
- invocation.Method.ReturnType.GetGenericArguments()[0]
- );
- }
- }
-
- private async Task