Browse Source
Merge pull request #410 from colinin/4.4.2
feat(wrapper): 提供忽略特定接口处理返回值
pull/426/head
yx lin
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with
66 additions and
6 deletions
-
aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/AbpWrapperOptions.cs
-
aspnet-core/modules/common/LINGYUN.Abp.Wrapper/LINGYUN/Abp/Wrapper/IWrapDisabled.cs
-
aspnet-core/modules/dapr/LINGYUN.Abp.Dapr.Actors.AspNetCore/LINGYUN/Abp/Dapr/Actors/AspNetCore/AbpDaprActorsAspNetCoreModule.cs
-
aspnet-core/modules/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/LINGYUN/Abp/AspNetCore/Mvc/Wrapper/WrapResultChecker.cs
-
aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs
-
aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/DontWrapResultBaseTypeController.cs
-
aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/DontWrapResultController.cs
-
aspnet-core/tests/LINGYUN.Abp.AspNetCore.Mvc.Tests/LINGYUN/Abp/AspNetCore/Mvc/Results/WrapResultController_Tests.cs
|
|
|
@ -61,9 +61,9 @@ namespace LINGYUN.Abp.Wrapper |
|
|
|
/// </summary>
|
|
|
|
public ITypeList<Exception> IgnoreExceptions { get; } |
|
|
|
/// <summary>
|
|
|
|
/// 忽略服务类型
|
|
|
|
/// 忽略接口类型
|
|
|
|
/// </summary>
|
|
|
|
public ITypeList IgnoreBaseTypes { get; } |
|
|
|
public ITypeList IgnoredInterfaces { get; } |
|
|
|
|
|
|
|
internal IDictionary<Type, IExceptionWrapHandler> ExceptionHandles { get; } |
|
|
|
|
|
|
|
@ -79,7 +79,10 @@ namespace LINGYUN.Abp.Wrapper |
|
|
|
|
|
|
|
IgnoreControllers = new TypeList(); |
|
|
|
IgnoreReturnTypes = new TypeList(); |
|
|
|
IgnoreBaseTypes = new TypeList(); |
|
|
|
IgnoredInterfaces = new TypeList() |
|
|
|
{ |
|
|
|
typeof(IWrapDisabled) |
|
|
|
}; |
|
|
|
IgnoreExceptions = new TypeList<Exception>(); |
|
|
|
|
|
|
|
CodeWithEmptyResult = (_) => "404"; |
|
|
|
|
|
|
|
@ -0,0 +1,6 @@ |
|
|
|
namespace LINGYUN.Abp.Wrapper |
|
|
|
{ |
|
|
|
public interface IWrapDisabled |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
@ -33,7 +33,7 @@ namespace LINGYUN.Abp.Dapr.Actors.AspNetCore |
|
|
|
|
|
|
|
Configure<AbpWrapperOptions>(options => |
|
|
|
{ |
|
|
|
options.IgnoreBaseTypes.TryAdd<IActor>(); |
|
|
|
options.IgnoredInterfaces.TryAdd<IActor>(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc.Filters; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using System; |
|
|
|
using System.Linq; |
|
|
|
using System.Reflection; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
using Volo.Abp.Threading; |
|
|
|
|
|
|
|
@ -70,6 +71,11 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (!CheckForInterfaces(descriptor)) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (!CheckForMethod(descriptor)) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
@ -123,6 +129,12 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Wrapper |
|
|
|
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) |
|
|
|
{ |
|
|
|
var returnType = AsyncHelper.UnwrapTask(controllerActionDescriptor.MethodInfo.ReturnType); |
|
|
|
|
|
|
|
@ -80,10 +80,12 @@ namespace LINGYUN.Abp.AspNetCore.Mvc |
|
|
|
options.IgnoreExceptions.Clear(); |
|
|
|
options.IgnoreNamespaces.Clear(); |
|
|
|
options.IgnorePrefixUrls.Clear(); |
|
|
|
options.IgnoredInterfaces.Clear(); |
|
|
|
options.IgnoreReturnTypes.Clear(); |
|
|
|
|
|
|
|
// api/abp/api-definition
|
|
|
|
options.IgnoreControllers.Add<AbpApiDefinitionController>(); |
|
|
|
options.IgnoredInterfaces.Add<IWrapDisabled>(); |
|
|
|
// api/abp/application-configuration
|
|
|
|
options.IgnoreReturnTypes.Add<ApplicationConfigurationDto>(); |
|
|
|
options.IgnoreReturnTypes.Add<IRemoteStreamContent>(); |
|
|
|
|
|
|
|
@ -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" } |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -17,7 +17,7 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Results |
|
|
|
DateTime = Clock.Now, |
|
|
|
Double = 3.141592653d, |
|
|
|
Integer = 100, |
|
|
|
Name = "Not Wrap", |
|
|
|
Name = "Not Wrap For Url Prefix", |
|
|
|
Properties = new Dictionary<string, string> |
|
|
|
{ |
|
|
|
{ "TestKey", "TestValue" } |
|
|
|
|
|
|
|
@ -39,7 +39,15 @@ namespace LINGYUN.Abp.AspNetCore.Mvc.Results |
|
|
|
{ |
|
|
|
var result = await GetResponseAsObjectAsync<TestResultObject>("/api/dont/wrap-result-test"); |
|
|
|
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] |
|
|
|
|