Browse Source

feat(wrapper): 增加对于dapr的包装结果处理

pull/409/head
cKey 4 years ago
parent
commit
0abd02d162
  1. 9
      aspnet-core/LINGYUN.MicroService.Common.sln
  2. 18
      aspnet-core/modules/common/LINGYUN.Abp.HttpClient.Wrapper/LINGYUN.Abp.HttpClient.Wrapper.csproj
  3. 13
      aspnet-core/modules/common/LINGYUN.Abp.HttpClient.Wrapper/LINGYUN/Abp/HttpClient/Wrapper/AbpHttpClientWrapperModule.cs
  4. 153
      aspnet-core/modules/common/LINGYUN.Abp.HttpClient.Wrapper/LINGYUN/Abp/HttpClient/Wrapper/DynamicHttpProxyInterceptorWrapClientProxy.cs
  5. 2
      aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/AbpHttpWrapConsts.cs
  6. 69
      aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/AbpWrapperOptions.cs
  7. 4
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN.Abp.Dapr.Actors.AspNetCore.csproj
  8. 9
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN/Abp/Dapr/Actors/AspNetCore/AbpDaprActorsAspNetCoreModule.cs
  9. 1
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN.Abp.Dapr.Client.csproj
  10. 6
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/AbpDaprClientModule.cs
  11. 46
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN/Abp/Dapr/Client/DynamicProxying/DynamicDaprClientProxyInterceptor.cs
  12. 2
      aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/AbpAspNetCoreMvcWrapperModule.cs
  13. 70
      aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/AbpAspNetCoreMvcWrapperOptions.cs
  14. 4
      aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionPageWrapResultFilter.cs
  15. 4
      aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionWrapResultFilter.cs
  16. 1
      aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/Filters/AbpWrapResultFilter.cs
  17. 6
      aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/WrapResultChecker.cs
  18. 2
      aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/Wraping/EmptyActionResultWrapper.cs
  19. 4
      aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/Wraping/JsonActionResultWrapper.cs
  20. 12
      aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/Wraping/ObjectActionResultWrapper.cs
  21. 3
      aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs
  22. 2
      aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/WrapResultController_Tests.cs
  23. 2
      aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/LINGYUN.Abp.Dapr.AspNetCore.TestHost.csproj
  24. 18
      aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/LINGYUN/Abp/Dapr/AbpDaprAspNetCoreTestHostModule.cs
  25. 12
      aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/LINGYUN/Abp/Dapr/ServiceInvocation/TestAppService.cs
  26. 8
      aspnet-core/tests/LINGYUN.Abp.Dapr.Client.Tests/LINGYUN/Abp/Dapr/Client/Tests/TestAppServiceTests.cs
  27. 1
      aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/AbpDaprTestModule.cs
  28. 2
      aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/ServiceInvocation/ITestAppService.cs
  29. 7
      aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/TestNeedWrapObject.cs

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

@ -204,7 +204,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.AspNetCore.Test
EndProject 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}" 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 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution 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}.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.ActiveCfg = Release|Any CPU
{31AED9ED-29BD-4F2F-8D3A-F00CBB9FC73C}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -639,6 +645,7 @@ Global
{BD4165DB-F8A4-4715-A05A-CC08F6A18D67} = {B86C21A4-73B7-471E-B73A-B4B905EC9435} {BD4165DB-F8A4-4715-A05A-CC08F6A18D67} = {B86C21A4-73B7-471E-B73A-B4B905EC9435}
{AE5E6DE8-FC02-4633-BA49-C4B8ABADB502} = {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} {31AED9ED-29BD-4F2F-8D3A-F00CBB9FC73C} = {B86C21A4-73B7-471E-B73A-B4B905EC9435}
{F6CABEE7-DE34-458A-8787-95DFB1DA4762} = {086BE5BE-8594-4DA7-8819-935FEF76DABD}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {06C707C6-02C0-411A-AD3B-2D0E13787CB8} SolutionGuid = {06C707C6-02C0-411A-AD3B-2D0E13787CB8}

18
aspnet-core/modules/common/LINGYUN.Abp.HttpClient.Wrapper/LINGYUN.Abp.HttpClient.Wrapper.csproj

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Http.Client" Version="5.0.0-rc.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LINGYUN.Abp.Wrapper\LINGYUN.Abp.Wrapper.csproj" />
</ItemGroup>
</Project>

13
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
{
}
}

153
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<TService>
: DynamicHttpProxyInterceptorClientProxy<TService>, ITransientDependency
{
protected IOptions<AbpWrapperOptions> WrapperOptions => LazyServiceProvider.LazyGetRequiredService<IOptions<AbpWrapperOptions>>();
protected override async Task<T> RequestAsync<T>(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<WrapResult<T>>(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<T>(stringContent);
}
public override async Task<HttpContent> CallRequestAsync(ClientProxyRequestContext requestContext)
{
var response = await RequestAndGetResponseAsync(requestContext);
// 对于包装后的结果需要处理
if (response.Headers.Contains(AbpHttpWrapConsts.AbpWrapResult))
{
var stringContent = await response.Content.ReadAsStringAsync();
var wrapResult = JsonSerializer.Deserialize<WrapResult>(stringContent);
ThrowExceptionForResponse(wrapResult);
}
return response.Content;
}
protected virtual void ThrowExceptionForResponse<T>(WrapResult<T> 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<HttpResponseMessage> 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;
}
}
}

2
aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/AbpHttpWrapConsts.cs → 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 public static class AbpHttpWrapConsts
{ {

69
aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/AbpWrapperOptions.cs

@ -1,5 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net;
using Volo.Abp.Collections;
namespace LINGYUN.Abp.Wrapper namespace LINGYUN.Abp.Wrapper
{ {
@ -10,12 +12,79 @@ namespace LINGYUN.Abp.Wrapper
/// 默认: 500 /// 默认: 500
/// </summary> /// </summary>
public string CodeWithUnhandled { get; set; } public string CodeWithUnhandled { get; set; }
/// <summary>
/// 是否启用包装器
/// </summary>
public bool IsEnabled { get; set; }
/// <summary>
/// 成功时返回代码
/// 默认:0
/// </summary>
public string CodeWithSuccess { get; set; }
/// <summary>
/// 资源为空时是否提示错误
/// 默认: false
/// </summary>
public bool ErrorWithEmptyResult { get; set; }
/// <summary>
/// 资源为空时返回代码
/// 默认:404
/// </summary>
public Func<IServiceProvider, string> CodeWithEmptyResult { get; set; }
/// <summary>
/// 资源为空时返回错误消息
/// </summary>
public Func<IServiceProvider, string> MessageWithEmptyResult { get; set; }
/// <summary>
/// 包装后的返回状态码
/// 默认:200 HttpStatusCode.OK
/// </summary>
public HttpStatusCode HttpStatusCode { get; set; }
/// <summary>
/// 忽略Url开头类型
/// </summary>
public IList<string> IgnorePrefixUrls { get; }
/// <summary>
/// 忽略指定命名空间
/// </summary>
public IList<string> IgnoreNamespaces { get; }
/// <summary>
/// 忽略控制器
/// </summary>
public ITypeList IgnoreControllers { get; }
/// <summary>
/// 忽略返回值
/// </summary>
public ITypeList IgnoreReturnTypes { get; }
/// <summary>
/// 忽略异常
/// </summary>
public ITypeList<Exception> IgnoreExceptions { get; }
/// <summary>
/// 忽略服务类型
/// </summary>
public ITypeList IgnoreBaseTypes { get; }
internal IDictionary<Type, IExceptionWrapHandler> ExceptionHandles { get; } internal IDictionary<Type, IExceptionWrapHandler> ExceptionHandles { get; }
public AbpWrapperOptions() public AbpWrapperOptions()
{ {
CodeWithUnhandled = "500"; CodeWithUnhandled = "500";
CodeWithSuccess = "0";
HttpStatusCode = HttpStatusCode.OK;
ErrorWithEmptyResult = false;
IgnorePrefixUrls = new List<string>();
IgnoreNamespaces = new List<string>();
IgnoreControllers = new TypeList();
IgnoreReturnTypes = new TypeList();
IgnoreBaseTypes = new TypeList();
IgnoreExceptions = new TypeList<Exception>();
CodeWithEmptyResult = (_) => "404";
MessageWithEmptyResult = (_) => "Not Found";
ExceptionHandles = new Dictionary<Type, IExceptionWrapHandler>(); ExceptionHandles = new Dictionary<Type, IExceptionWrapHandler>();
} }

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

@ -12,4 +12,8 @@
<PackageReference Include="Volo.Abp.AspNetCore" Version="4.4.0" /> <PackageReference Include="Volo.Abp.AspNetCore" Version="4.4.0" />
</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,5 +1,6 @@
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;
@ -11,7 +12,8 @@ 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)
@ -28,6 +30,11 @@ namespace LINGYUN.Abp.Dapr.Actors.AspNetCore
endpointContext.Endpoints.MapActorsHandlers(); endpointContext.Endpoints.MapActorsHandlers();
}); });
}); });
Configure<AbpWrapperOptions>(options =>
{
options.IgnoreBaseTypes.TryAdd<IActor>();
});
} }
private static void AddDefinitionActor(IServiceCollection services) private static void AddDefinitionActor(IServiceCollection services)

1
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Client/LINGYUN.Abp.Dapr.Client.csproj

@ -12,6 +12,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\common\LINGYUN.Abp.Wrapper\LINGYUN.Abp.Wrapper.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.Dapr\LINGYUN.Abp.Dapr.csproj" /> <ProjectReference Include="..\LINGYUN.Abp.Dapr\LINGYUN.Abp.Dapr.csproj" />
</ItemGroup> </ItemGroup>

6
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.Http.Client;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
namespace LINGYUN.Abp.Dapr.Client namespace LINGYUN.Abp.Dapr.Client
{ {
[DependsOn( [DependsOn(
typeof(AbpHttpClientModule) typeof(AbpHttpClientModule),
typeof(AbpWrapperModule)
)] )]
public class AbpDaprClientModule : AbpModule public class AbpDaprClientModule : AbpModule
{ {

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

@ -1,4 +1,5 @@
using Dapr.Client; using Dapr.Client;
using LINGYUN.Abp.Wrapper;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
@ -41,6 +42,7 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
protected IDaprApiDescriptionFinder ApiDescriptionFinder { get; } protected IDaprApiDescriptionFinder ApiDescriptionFinder { get; }
protected AbpDaprRemoteServiceOptions AbpRemoteServiceOptions { get; } protected AbpDaprRemoteServiceOptions AbpRemoteServiceOptions { get; }
protected AbpDaprClientProxyOptions ClientProxyOptions { get; } protected AbpDaprClientProxyOptions ClientProxyOptions { get; }
protected AbpWrapperOptions WrapperOptions { get; }
protected IJsonSerializer JsonSerializer { get; } protected IJsonSerializer JsonSerializer { get; }
protected IRemoteServiceHttpClientAuthenticator ClientAuthenticator { get; } protected IRemoteServiceHttpClientAuthenticator ClientAuthenticator { get; }
@ -64,6 +66,7 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
ICancellationTokenProvider cancellationTokenProvider, ICancellationTokenProvider cancellationTokenProvider,
ICorrelationIdProvider correlationIdProvider, ICorrelationIdProvider correlationIdProvider,
IOptions<AbpCorrelationIdOptions> correlationIdOptions, IOptions<AbpCorrelationIdOptions> correlationIdOptions,
IOptions<AbpWrapperOptions> wrapperOptions,
ICurrentTenant currentTenant) ICurrentTenant currentTenant)
{ {
DaprClientFactory = daprClientFactory; DaprClientFactory = daprClientFactory;
@ -77,6 +80,7 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
ClientAuthenticator = clientAuthenticator; ClientAuthenticator = clientAuthenticator;
ClientProxyOptions = clientProxyOptions.Value; ClientProxyOptions = clientProxyOptions.Value;
AbpRemoteServiceOptions = remoteServiceOptions.Value; AbpRemoteServiceOptions = remoteServiceOptions.Value;
WrapperOptions = wrapperOptions.Value;
Logger = NullLogger<DynamicDaprClientProxyInterceptor<TService>>.Instance; Logger = NullLogger<DynamicDaprClientProxyInterceptor<TService>>.Instance;
} }
@ -111,7 +115,8 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
private async Task<T> MakeRequestAndGetResultAsync<T>(IAbpMethodInvocation invocation) private async Task<T> MakeRequestAndGetResultAsync<T>(IAbpMethodInvocation invocation)
{ {
var responseContent = await MakeRequestAsync(invocation); var response = await MakeRequestAsync(invocation);
var responseContent = response.Content;
if (typeof(T) == typeof(IRemoteStreamContent)) if (typeof(T) == typeof(IRemoteStreamContent))
{ {
@ -123,22 +128,47 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
ContentType = responseContent.Headers.ContentType?.ToString() ContentType = responseContent.Headers.ContentType?.ToString()
}; };
} }
var stringContent = await responseContent.ReadAsStringAsync(); var stringContent = await responseContent.ReadAsStringAsync();
if (typeof(T) == typeof(string))
{
return (T)(object)stringContent;
}
if (stringContent.IsNullOrWhiteSpace()) if (stringContent.IsNullOrWhiteSpace())
{ {
return default; return default;
} }
// 对于包装后的结果需要处理
if (response.Headers.Contains(AbpHttpWrapConsts.AbpWrapResult))
{
var wrapResult = JsonSerializer.Deserialize<WrapResult<T>>(stringContent);
if (!string.Equals(wrapResult.Code, WrapperOptions.CodeWithSuccess))
{
var errorInfo = new RemoteServiceErrorInfo(
wrapResult.Message,
wrapResult.Details,
wrapResult.Code);
throw new AbpRemoteCallException(errorInfo)
{
HttpStatusCode = (int)WrapperOptions.HttpStatusCode
};
}
if (typeof(T) == typeof(string))
{
return (T)(object)wrapResult.Result;
}
return wrapResult.Result;
}
if (typeof(T) == typeof(string))
{
return (T)(object)stringContent;
}
return JsonSerializer.Deserialize<T>(stringContent); return JsonSerializer.Deserialize<T>(stringContent);
} }
private async Task<HttpContent> MakeRequestAsync(IAbpMethodInvocation invocation) private async Task<HttpResponseMessage> MakeRequestAsync(IAbpMethodInvocation invocation)
{ {
var clientConfig = ClientProxyOptions.DaprClientProxies.GetOrDefault(typeof(TService)) ?? throw new AbpException($"Could not get DynamicDaprClientProxyConfig for {typeof(TService).FullName}."); var clientConfig = ClientProxyOptions.DaprClientProxies.GetOrDefault(typeof(TService)) ?? throw new AbpException($"Could not get DynamicDaprClientProxyConfig for {typeof(TService).FullName}.");
var remoteServiceConfig = AbpRemoteServiceOptions.RemoteServices.GetConfigurationOrDefault(clientConfig.RemoteServiceName); var remoteServiceConfig = AbpRemoteServiceOptions.RemoteServices.GetConfigurationOrDefault(clientConfig.RemoteServiceName);
@ -190,7 +220,7 @@ namespace LINGYUN.Abp.Dapr.Client.DynamicProxying
await ThrowExceptionForResponseAsync(response); await ThrowExceptionForResponseAsync(response);
} }
return response.Content; return response;
} }
private ApiVersionInfo GetApiVersionInfo(ActionApiDescriptionModel action) private ApiVersionInfo GetApiVersionInfo(ActionApiDescriptionModel action)

2
aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/AbpAspNetCoreMvcWrapperModule.cs

@ -41,7 +41,7 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper
mvcOptions.Filters.AddService(typeof(AbpWrapResultFilter)); mvcOptions.Filters.AddService(typeof(AbpWrapResultFilter));
}); });
Configure<AbpAspNetCoreMvcWrapperOptions>(options => Configure<AbpWrapperOptions>(options =>
{ {
// 即使重写端点也不包装返回结果 // 即使重写端点也不包装返回结果
// api/abp/api-definition // api/abp/api-definition

70
aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/AbpAspNetCoreMvcWrapperOptions.cs

@ -1,70 +0,0 @@
using System;
using System.Collections.Generic;
using System.Net;
using Volo.Abp.Collections;
namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper
{
public class AbpAspNetCoreMvcWrapperOptions
{
/// <summary>
/// 是否启用包装器
/// </summary>
public bool IsEnabled { get; set; }
/// <summary>
/// 资源有效时返回代码
/// 默认:0
/// </summary>
public string CodeWithFound { get; set; }
/// <summary>
/// 资源为空时返回代码
/// 默认:404
/// </summary>
public Func<IServiceProvider, string> CodeWithEmptyResult { get; set; }
/// <summary>
/// 资源为空时返回错误消息
/// </summary>
public Func<IServiceProvider, string> MessageWithEmptyResult { get; set; }
/// <summary>
/// 包装后的返回状态码
/// 默认:200 HttpStatusCode.OK
/// </summary>
public HttpStatusCode HttpStatusCode { get; set; }
/// <summary>
/// 忽略Url开头类型
/// </summary>
public IList<string> IgnorePrefixUrls { get; }
/// <summary>
/// 忽略指定命名空间
/// </summary>
public IList<string> IgnoreNamespaces { get; }
/// <summary>
/// 忽略控制器
/// </summary>
public ITypeList IgnoreControllers { get; }
/// <summary>
/// 忽略返回值
/// </summary>
public ITypeList IgnoreReturnTypes { get; }
/// <summary>
/// 忽略异常
/// </summary>
public ITypeList<Exception> IgnoreExceptions { get; }
public AbpAspNetCoreMvcWrapperOptions()
{
CodeWithFound = "0";
HttpStatusCode = HttpStatusCode.OK;
IgnorePrefixUrls = new List<string>();
IgnoreNamespaces = new List<string>();
IgnoreControllers = new TypeList();
IgnoreReturnTypes = new TypeList();
IgnoreExceptions = new TypeList<Exception>();
CodeWithEmptyResult = (_) => "404";
MessageWithEmptyResult = (_) => "Not Found";
}
}
}

4
aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionPageWrapResultFilter.cs

@ -30,7 +30,7 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper.ExceptionHandling
return; return;
} }
var wrapResultOptions = context.GetRequiredService<IOptions<AbpAspNetCoreMvcWrapperOptions>>().Value; var wrapOptions = context.GetRequiredService<IOptions<AbpWrapperOptions>>().Value;
var exceptionHandlingOptions = context.GetRequiredService<IOptions<AbpExceptionHandlingOptions>>().Value; var exceptionHandlingOptions = context.GetRequiredService<IOptions<AbpExceptionHandlingOptions>>().Value;
var exceptionToErrorInfoConverter = context.GetRequiredService<IExceptionToErrorInfoConverter>(); var exceptionToErrorInfoConverter = context.GetRequiredService<IExceptionToErrorInfoConverter>();
var remoteServiceErrorInfo = exceptionToErrorInfoConverter.Convert(context.Exception, exceptionHandlingOptions.SendExceptionsDetailsToClients); var remoteServiceErrorInfo = exceptionToErrorInfoConverter.Convert(context.Exception, exceptionHandlingOptions.SendExceptionsDetailsToClients);
@ -58,7 +58,7 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper.ExceptionHandling
context.Result = new ObjectResult(wrapResult); context.Result = new ObjectResult(wrapResult);
context.HttpContext.Response.Headers.Add(AbpHttpWrapConsts.AbpWrapResult, "true"); context.HttpContext.Response.Headers.Add(AbpHttpWrapConsts.AbpWrapResult, "true");
context.HttpContext.Response.StatusCode = (int)wrapResultOptions.HttpStatusCode; context.HttpContext.Response.StatusCode = (int)wrapOptions.HttpStatusCode;
context.Exception = null; //Handled! context.Exception = null; //Handled!
} }

4
aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionWrapResultFilter.cs

@ -32,7 +32,7 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper.ExceptionHandling
return; return;
} }
//TODO: Trigger an AbpExceptionHandled event or something like that. //TODO: Trigger an AbpExceptionHandled event or something like that.
var wrapResultOptions = context.GetRequiredService<IOptions<AbpAspNetCoreMvcWrapperOptions>>().Value; var wrapOptions = context.GetRequiredService<IOptions<AbpWrapperOptions>>().Value;
var exceptionHandlingOptions = context.GetRequiredService<IOptions<AbpExceptionHandlingOptions>>().Value; var exceptionHandlingOptions = context.GetRequiredService<IOptions<AbpExceptionHandlingOptions>>().Value;
var exceptionToErrorInfoConverter = context.GetRequiredService<IExceptionToErrorInfoConverter>(); var exceptionToErrorInfoConverter = context.GetRequiredService<IExceptionToErrorInfoConverter>();
var remoteServiceErrorInfo = exceptionToErrorInfoConverter.Convert(context.Exception, exceptionHandlingOptions.SendExceptionsDetailsToClients); var remoteServiceErrorInfo = exceptionToErrorInfoConverter.Convert(context.Exception, exceptionHandlingOptions.SendExceptionsDetailsToClients);
@ -61,7 +61,7 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper.ExceptionHandling
context.Result = new ObjectResult(wrapResult); context.Result = new ObjectResult(wrapResult);
context.HttpContext.Response.Headers.Add(AbpHttpWrapConsts.AbpWrapResult, "true"); context.HttpContext.Response.Headers.Add(AbpHttpWrapConsts.AbpWrapResult, "true");
context.HttpContext.Response.StatusCode = (int)wrapResultOptions.HttpStatusCode; context.HttpContext.Response.StatusCode = (int)wrapOptions.HttpStatusCode;
context.Exception = null; //Handled! context.Exception = null; //Handled!
} }

1
aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/Filters/AbpWrapResultFilter.cs

@ -1,4 +1,5 @@
using LINGYUN.Abp.AspNetCore.Mvc.Wrapper.Wraping; using LINGYUN.Abp.AspNetCore.Mvc.Wrapper.Wraping;
using LINGYUN.Abp.Wrapper;
using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.Filters;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc;

6
aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/WrapResultChecker.cs

@ -6,18 +6,16 @@ using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using System; using System;
using System.Linq; using System.Linq;
using System.Reflection;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Http;
using Volo.Abp.Threading; using Volo.Abp.Threading;
namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper
{ {
public class WrapResultChecker : IWrapResultChecker, ISingletonDependency public class WrapResultChecker : IWrapResultChecker, ISingletonDependency
{ {
protected AbpAspNetCoreMvcWrapperOptions Options { get; } protected AbpWrapperOptions Options { get; }
public WrapResultChecker(IOptionsMonitor<AbpAspNetCoreMvcWrapperOptions> optionsMonitor) public WrapResultChecker(IOptionsMonitor<AbpWrapperOptions> optionsMonitor)
{ {
Options = optionsMonitor.CurrentValue; Options = optionsMonitor.CurrentValue;
} }

2
aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/Wraping/EmptyActionResultWrapper.cs

@ -10,7 +10,7 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper.Wraping
{ {
public void Wrap(FilterContext context) public void Wrap(FilterContext context)
{ {
var options = context.GetRequiredService<IOptions<AbpAspNetCoreMvcWrapperOptions>>().Value; var options = context.GetRequiredService<IOptions<AbpWrapperOptions>>().Value;
var code = options.CodeWithEmptyResult(context.HttpContext.RequestServices); var code = options.CodeWithEmptyResult(context.HttpContext.RequestServices);
var message = options.MessageWithEmptyResult(context.HttpContext.RequestServices); var message = options.MessageWithEmptyResult(context.HttpContext.RequestServices);
switch (context) switch (context)

4
aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/Wraping/JsonActionResultWrapper.cs

@ -31,9 +31,9 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper.Wraping
if (!(jsonResult.Value is WrapResult)) if (!(jsonResult.Value is WrapResult))
{ {
var options = context.GetRequiredService<IOptions<AbpAspNetCoreMvcWrapperOptions>>().Value; var options = context.GetRequiredService<IOptions<AbpWrapperOptions>>().Value;
jsonResult.Value = new WrapResult(options.CodeWithFound, jsonResult.Value); jsonResult.Value = new WrapResult(options.CodeWithSuccess, jsonResult.Value);
} }
} }
} }

12
aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/Wraping/ObjectActionResultWrapper.cs

@ -31,18 +31,18 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper.Wraping
if (!(objectResult.Value is WrapResult)) if (!(objectResult.Value is WrapResult))
{ {
var options = context.GetRequiredService<IOptions<AbpAspNetCoreMvcWrapperOptions>>().Value; var options = context.GetRequiredService<IOptions<AbpWrapperOptions>>().Value;
if (objectResult.Value != null) if (objectResult.Value == null && options.ErrorWithEmptyResult)
{
objectResult.Value = new WrapResult(options.CodeWithFound, objectResult.Value);
}
else
{ {
var code = options.CodeWithEmptyResult(context.HttpContext.RequestServices); var code = options.CodeWithEmptyResult(context.HttpContext.RequestServices);
var message = options.MessageWithEmptyResult(context.HttpContext.RequestServices); var message = options.MessageWithEmptyResult(context.HttpContext.RequestServices);
objectResult.Value = new WrapResult(code, message); objectResult.Value = new WrapResult(code, message);
} }
else
{
objectResult.Value = new WrapResult(options.CodeWithSuccess, objectResult.Value);
}
objectResult.DeclaredType = typeof(WrapResult); objectResult.DeclaredType = typeof(WrapResult);
} }

3
aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs

@ -2,6 +2,7 @@
using LINGYUN.Abp.AspNetCore.Mvc.Localization; using LINGYUN.Abp.AspNetCore.Mvc.Localization;
using LINGYUN.Abp.AspNetCore.Mvc.Results; using LINGYUN.Abp.AspNetCore.Mvc.Results;
using LINGYUN.Abp.AspNetCore.Mvc.Wrapper; using LINGYUN.Abp.AspNetCore.Mvc.Wrapper;
using LINGYUN.Abp.Wrapper;
using Localization.Resources.AbpUi; using Localization.Resources.AbpUi;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
@ -70,7 +71,7 @@ namespace LINGYUN.Abp.AspNetCore.Mvc
{ {
}); });
Configure<AbpAspNetCoreMvcWrapperOptions>(options => Configure<AbpWrapperOptions>(options =>
{ {
options.IsEnabled = true; options.IsEnabled = true;

2
aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/WrapResultController_Tests.cs

@ -86,7 +86,7 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Results
public async Task Should_Return_Wrap_Result_For_Empty_Object_Return_Value() public async Task Should_Return_Wrap_Result_For_Empty_Object_Return_Value()
{ {
var result = await GetResponseAsObjectAsync<WrapResult<TestResultObject>>("/api/wrap-result-test/wrap-empty"); var result = await GetResponseAsObjectAsync<WrapResult<TestResultObject>>("/api/wrap-result-test/wrap-empty");
result.Code.ShouldBe("404"); result.Code.ShouldBe("0");
result.Result.ShouldBeNull(); result.Result.ShouldBeNull();
} }

2
aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/LINGYUN.Abp.Dapr.AspNetCore.TestHost.csproj

@ -11,7 +11,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\modules\common\LINGYUN.Abp.Wrapper\LINGYUN.Abp.Wrapper.csproj" />
<ProjectReference Include="..\..\modules\dapr\LINGYUN.Abp.Dapr.Actors.AspNetCore\LINGYUN.Abp.Dapr.Actors.AspNetCore.csproj" /> <ProjectReference Include="..\..\modules\dapr\LINGYUN.Abp.Dapr.Actors.AspNetCore\LINGYUN.Abp.Dapr.Actors.AspNetCore.csproj" />
<ProjectReference Include="..\..\modules\mvc\LINGYUN.Abp.AspNetCore.Mvc.Wrapper\LINGYUN.Abp.AspNetCore.Mvc.Wrapper.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.Dapr.Tests\LINGYUN.Abp.Dapr.Tests.csproj" /> <ProjectReference Include="..\LINGYUN.Abp.Dapr.Tests\LINGYUN.Abp.Dapr.Tests.csproj" />
</ItemGroup> </ItemGroup>

18
aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/LINGYUN/Abp/Dapr/AbpDaprAspNetCoreTestHostModule.cs

@ -1,15 +1,19 @@
using LINGYUN.Abp.Dapr.Actors.AspNetCore; using LINGYUN.Abp.AspNetCore.Mvc.Wrapper;
using LINGYUN.Abp.Dapr.Actors.AspNetCore;
using LINGYUN.Abp.Dapr.ServiceInvocation;
using LINGYUN.Abp.Wrapper;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
namespace LINGYUN.Abp.Dapr namespace LINGYUN.Abp.Dapr
{ {
[DependsOn( [DependsOn(
typeof(AbpAspNetCoreMvcModule), typeof(AbpDaprActorsAspNetCoreModule),
typeof(AbpDaprActorsAspNetCoreModule) typeof(AbpAspNetCoreMvcWrapperModule)
)] )]
public class AbpDaprAspNetCoreTestHostModule : AbpModule public class AbpDaprAspNetCoreTestHostModule : AbpModule
{ {
@ -25,6 +29,14 @@ namespace LINGYUN.Abp.Dapr
{ {
var hostingEnvironment = context.Services.GetHostingEnvironment(); var hostingEnvironment = context.Services.GetHostingEnvironment();
var configuration = context.Services.GetConfiguration(); var configuration = context.Services.GetConfiguration();
Configure<AbpWrapperOptions>(options =>
{
options.IsEnabled = true;
options.IgnoreReturnTypes.TryAdd<NameValue>();
options.IgnoreReturnTypes.TryAdd<ListResultDto<NameValue>>();
});
} }
public override void OnApplicationInitialization(ApplicationInitializationContext context) public override void OnApplicationInitialization(ApplicationInitializationContext context)

12
aspnet-core/tests/LINGYUN.Abp.Dapr.AspNetCore.TestHost/LINGYUN/Abp/Dapr/ServiceInvocation/TestAppService.cs

@ -37,5 +37,17 @@ namespace LINGYUN.Abp.Dapr.ServiceInvocation
return Task.FromResult(_cache[0]); return Task.FromResult(_cache[0]);
} }
[HttpGet]
[Route("{name}")]
public Task<TestNeedWrapObject> GetWrapedAsync(string name)
{
var obj = new TestNeedWrapObject
{
Name = name
};
return Task.FromResult(obj);
}
} }
} }

8
aspnet-core/tests/LINGYUN.Abp.Dapr.Client.Tests/LINGYUN/Abp/Dapr/Client/Tests/TestAppServiceTests.cs

@ -22,6 +22,14 @@ namespace LINGYUN.Abp.Dapr.Client.Tests
result.Items.Count.ShouldBe(5); result.Items.Count.ShouldBe(5);
} }
[Fact]
public async Task Should_Get_Wraped_Object()
{
var result = await _service.GetWrapedAsync("Test");
result.Name.ShouldBe("Test");
}
[Fact] [Fact]
public async Task Update_Result_Value_Should_Value_Updated_1() public async Task Update_Result_Value_Should_Value_Updated_1()
{ {

1
aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/AbpDaprTestModule.cs

@ -7,5 +7,6 @@ namespace LINGYUN.Abp.Dapr
typeof(AbpDddApplicationContractsModule))] typeof(AbpDddApplicationContractsModule))]
public class AbpDaprTestModule : AbpModule public class AbpDaprTestModule : AbpModule
{ {
} }
} }

2
aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/ServiceInvocation/ITestAppService.cs

@ -10,5 +10,7 @@ namespace LINGYUN.Abp.Dapr.ServiceInvocation
Task<ListResultDto<NameValue>> GetAsync(); Task<ListResultDto<NameValue>> GetAsync();
Task<NameValue> UpdateAsync(); Task<NameValue> UpdateAsync();
Task<TestNeedWrapObject> GetWrapedAsync(string name);
} }
} }

7
aspnet-core/tests/LINGYUN.Abp.Dapr.Tests/LINGYUN/Abp/Dapr/TestNeedWrapObject.cs

@ -0,0 +1,7 @@
namespace LINGYUN.Abp.Dapr
{
public class TestNeedWrapObject
{
public string Name { get; set; }
}
}
Loading…
Cancel
Save