Browse Source

Merge pull request #410 from colinin/4.4.2

feat(wrapper): 提供忽略特定接口处理返回值
pull/426/head
yx lin 4 years ago
committed by GitHub
parent
commit
03bf2c12ec
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/AbpWrapperOptions.cs
  2. 6
      aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/IWrapDisabled.cs
  3. 2
      aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN/Abp/Dapr/Actors/AspNetCore/AbpDaprActorsAspNetCoreModule.cs
  4. 12
      aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/WrapResultChecker.cs
  5. 2
      aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs
  6. 29
      aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/DontWrapResultBaseTypeController.cs
  7. 2
      aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/DontWrapResultController.cs
  8. 10
      aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/WrapResultController_Tests.cs

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

@ -61,9 +61,9 @@ namespace LINGYUN.Abp.Wrapper
/// </summary> /// </summary>
public ITypeList<Exception> IgnoreExceptions { get; } public ITypeList<Exception> IgnoreExceptions { get; }
/// <summary> /// <summary>
/// 忽略服务类型 /// 忽略接口类型
/// </summary> /// </summary>
public ITypeList IgnoreBaseTypes { get; } public ITypeList IgnoredInterfaces { get; }
internal IDictionary<Type, IExceptionWrapHandler> ExceptionHandles { get; } internal IDictionary<Type, IExceptionWrapHandler> ExceptionHandles { get; }
@ -79,7 +79,10 @@ namespace LINGYUN.Abp.Wrapper
IgnoreControllers = new TypeList(); IgnoreControllers = new TypeList();
IgnoreReturnTypes = new TypeList(); IgnoreReturnTypes = new TypeList();
IgnoreBaseTypes = new TypeList(); IgnoredInterfaces = new TypeList()
{
typeof(IWrapDisabled)
};
IgnoreExceptions = new TypeList<Exception>(); IgnoreExceptions = new TypeList<Exception>();
CodeWithEmptyResult = (_) => "404"; CodeWithEmptyResult = (_) => "404";

6
aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/IWrapDisabled.cs

@ -0,0 +1,6 @@
namespace LINGYUN.Abp.Wrapper
{
public interface IWrapDisabled
{
}
}

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

@ -33,7 +33,7 @@ namespace LINGYUN.Abp.Dapr.Actors.AspNetCore
Configure<AbpWrapperOptions>(options => Configure<AbpWrapperOptions>(options =>
{ {
options.IgnoreBaseTypes.TryAdd<IActor>(); options.IgnoredInterfaces.TryAdd<IActor>();
}); });
} }

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

@ -6,6 +6,7 @@ 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.Threading; using Volo.Abp.Threading;
@ -70,6 +71,11 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper
return false; return false;
} }
if (!CheckForInterfaces(descriptor))
{
return false;
}
if (!CheckForMethod(descriptor)) if (!CheckForMethod(descriptor))
{ {
return false; return false;
@ -123,6 +129,12 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper
controllerActionDescriptor.ControllerTypeInfo.Namespace.StartsWith(nsp)); controllerActionDescriptor.ControllerTypeInfo.Namespace.StartsWith(nsp));
} }
protected virtual bool CheckForInterfaces(ControllerActionDescriptor controllerActionDescriptor)
{
return !Options.IgnoredInterfaces.Any(type =>
type.IsAssignableFrom(controllerActionDescriptor.ControllerTypeInfo));
}
protected virtual bool CheckForReturnType(ControllerActionDescriptor controllerActionDescriptor) protected virtual bool CheckForReturnType(ControllerActionDescriptor controllerActionDescriptor)
{ {
var returnType = AsyncHelper.UnwrapTask(controllerActionDescriptor.MethodInfo.ReturnType); var returnType = AsyncHelper.UnwrapTask(controllerActionDescriptor.MethodInfo.ReturnType);

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

@ -80,10 +80,12 @@ namespace LINGYUN.Abp.AspNetCore.Mvc
options.IgnoreExceptions.Clear(); options.IgnoreExceptions.Clear();
options.IgnoreNamespaces.Clear(); options.IgnoreNamespaces.Clear();
options.IgnorePrefixUrls.Clear(); options.IgnorePrefixUrls.Clear();
options.IgnoredInterfaces.Clear();
options.IgnoreReturnTypes.Clear(); options.IgnoreReturnTypes.Clear();
// api/abp/api-definition // api/abp/api-definition
options.IgnoreControllers.Add<AbpApiDefinitionController>(); options.IgnoreControllers.Add<AbpApiDefinitionController>();
options.IgnoredInterfaces.Add<IWrapDisabled>();
// api/abp/application-configuration // api/abp/application-configuration
options.IgnoreReturnTypes.Add<ApplicationConfigurationDto>(); options.IgnoreReturnTypes.Add<ApplicationConfigurationDto>();
options.IgnoreReturnTypes.Add<IRemoteStreamContent>(); options.IgnoreReturnTypes.Add<IRemoteStreamContent>();

29
aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/DontWrapResultBaseTypeController.cs

@ -0,0 +1,29 @@
using LINGYUN.Abp.Wrapper;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using Volo.Abp.AspNetCore.Mvc;
namespace LINGYUN.Abp.AspNetCore.Mvc.Results
{
[Route("api/dont-base-type/wrap-result-test")]
public class DontWrapResultBaseTypeController : AbpController, IWrapDisabled
{
[HttpGet]
public TestResultObject Wrap()
{
return new TestResultObject
{
Id = Guid.NewGuid(),
DateTime = Clock.Now,
Double = 3.141592653d,
Integer = 100,
Name = "Not Wrap For Base Type",
Properties = new Dictionary<string, string>
{
{ "TestKey", "TestValue" }
}
};
}
}
}

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

@ -17,7 +17,7 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Results
DateTime = Clock.Now, DateTime = Clock.Now,
Double = 3.141592653d, Double = 3.141592653d,
Integer = 100, Integer = 100,
Name = "Not Wrap", Name = "Not Wrap For Url Prefix",
Properties = new Dictionary<string, string> Properties = new Dictionary<string, string>
{ {
{ "TestKey", "TestValue" } { "TestKey", "TestValue" }

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

@ -39,7 +39,15 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Results
{ {
var result = await GetResponseAsObjectAsync<TestResultObject>("/api/dont/wrap-result-test"); var result = await GetResponseAsObjectAsync<TestResultObject>("/api/dont/wrap-result-test");
result.ShouldNotBeNull(); result.ShouldNotBeNull();
result.Name.ShouldBe("Not Wrap"); result.Name.ShouldBe("Not Wrap For Url Prefix");
}
[Fact]
public async Task Should_Return_Not_Wrap_Result_For_Interfaces_With_Dont_Wrapper()
{
var result = await GetResponseAsObjectAsync<TestResultObject>("/api/dont-base-type/wrap-result-test");
result.ShouldNotBeNull();
result.Name.ShouldBe("Not Wrap For Base Type");
} }
[Fact] [Fact]

Loading…
Cancel
Save