Browse Source

WrapExtensions

master
wwwk 3 years ago
parent
commit
54bf28f7be
  1. 0
      Sanhe.Abp.Framework.sln
  2. 15
      modules/mvc/Sanhe.Abp.AspNetCore.Mvc.Wrapper/Microsoft/AspNetCore/Cors/AbpCorsPolicyBuilderExtensions.cs
  3. 27
      modules/mvc/Sanhe.Abp.AspNetCore.Mvc.Wrapper/Microsoft/AspNetCore/Mvc/ActionContextExtensions.cs
  4. 5
      modules/mvc/Sanhe.Abp.AspNetCore.Mvc.Wrapper/Sanhe.Abp.AspNetCore.Mvc.Wrapper.csproj
  5. 3
      modules/mvc/Sanhe.Abp.AspNetCore.Mvc.Wrapper/Sanhe/Abp/AspNetCore/Mvc/Wrapper/AbpAspNetCoreMvcWrapperModule.cs
  6. 11
      modules/mvc/Sanhe.Abp.AspNetCore.Mvc.Wrapper/Sanhe/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionPageWrapResultFilter.cs
  7. 11
      modules/mvc/Sanhe.Abp.AspNetCore.Mvc.Wrapper/Sanhe/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionWrapResultFilter.cs
  8. 7
      modules/mvc/Sanhe.Abp.AspNetCore.Mvc.Wrapper/Sanhe/Abp/AspNetCore/Mvc/Wrapper/Filters/AbpWrapResultFilter.cs

0
Sanhe.Abp.Startup.sln → Sanhe.Abp.Framework.sln

15
modules/mvc/Sanhe.Abp.AspNetCore.Mvc.Wrapper/Microsoft/AspNetCore/Cors/AbpCorsPolicyBuilderExtensions.cs

@ -0,0 +1,15 @@
using Microsoft.AspNetCore.Cors.Infrastructure;
using Sanhe.Abp.Wrapper;
namespace Microsoft.AspNetCore.Cors;
public static class AbpCorsPolicyBuilderExtensions
{
public static CorsPolicyBuilder WithAbpWrapExposedHeaders(this CorsPolicyBuilder corsPolicyBuilder)
{
return corsPolicyBuilder
.WithExposedHeaders(
AbpHttpWrapConsts.AbpWrapResult,
AbpHttpWrapConsts.AbpDontWrapResult);
}
}

27
modules/mvc/Sanhe.Abp.AspNetCore.Mvc.Wrapper/Microsoft/AspNetCore/Mvc/ActionContextExtensions.cs

@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Controllers;
using Sanhe.Abp.Wrapper;
namespace Microsoft.AspNetCore.Mvc;
public static class ActionContextExtensions
{
public static bool CanWarpRsult(this ActionDescriptor actionDescriptor)
{
if (actionDescriptor is ControllerActionDescriptor descriptor)
{
if (descriptor.MethodInfo.IsDefined(typeof(IgnoreWrapResultAttribute), true))
{
return false;
}
if (descriptor.ControllerTypeInfo.IsDefined(typeof(IgnoreWrapResultAttribute), true))
{
return false;
}
return true;
}
return false;
}
}

5
modules/mvc/Sanhe.Abp.AspNetCore.Mvc.Wrapper/Sanhe.Abp.AspNetCore.Mvc.Wrapper.csproj

@ -26,9 +26,4 @@
<ProjectReference Include="..\..\common\Sanhe.Abp.Wrapper\Sanhe.Abp.Wrapper.csproj" /> <ProjectReference Include="..\..\common\Sanhe.Abp.Wrapper\Sanhe.Abp.Wrapper.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Microsoft\AspNetCore\Cors\" />
<Folder Include="Microsoft\AspNetCore\Mvc\" />
</ItemGroup>
</Project> </Project>

3
modules/mvc/Sanhe.Abp.AspNetCore.Mvc.Wrapper/Sanhe/Abp/AspNetCore/Mvc/Wrapper/AbpAspNetCoreMvcWrapperModule.cs

@ -47,11 +47,10 @@ public class AbpAspNetCoreMvcWrapperModule : AbpModule
options.IgnoreReturnTypes.Add<ApplicationApiDescriptionModel>(); options.IgnoreReturnTypes.Add<ApplicationApiDescriptionModel>();
// api/abp/application-configuration // api/abp/application-configuration
options.IgnoreReturnTypes.Add<ApplicationConfigurationDto>(); options.IgnoreReturnTypes.Add<ApplicationConfigurationDto>();
// 流 // 流内容
options.IgnoreReturnTypes.Add<IRemoteStreamContent>(); options.IgnoreReturnTypes.Add<IRemoteStreamContent>();
// Abp/ServiceProxyScript // Abp/ServiceProxyScript
options.IgnoreControllers.Add<AbpServiceProxyScriptController>(); options.IgnoreControllers.Add<AbpServiceProxyScriptController>();
// 官方模块不包装结果 // 官方模块不包装结果
options.IgnoreNamespaces.Add("Volo.Abp"); options.IgnoreNamespaces.Add("Volo.Abp");

11
modules/mvc/Sanhe.Abp.AspNetCore.Mvc.Wrapper/Sanhe/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionPageWrapResultFilter.cs

@ -17,12 +17,12 @@ using Volo.Abp.ExceptionHandling;
using Volo.Abp.Http; using Volo.Abp.Http;
using Volo.Abp.Json; using Volo.Abp.Json;
namespace Sanhe.Abp.AspNetCore.Mvc.Wrapper.ExceptionHandling namespace Sanhe.Abp.AspNetCore.Mvc.Wrapper.ExceptionHandling;
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(AbpExceptionPageFilter))]
public class AbpExceptionPageWrapResultFilter : AbpExceptionPageFilter, ITransientDependency
{ {
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(AbpExceptionPageFilter))]
public class AbpExceptionPageWrapResultFilter : AbpExceptionPageFilter, ITransientDependency
{
protected async override Task HandleAndWrapException(PageHandlerExecutedContext context) protected async override Task HandleAndWrapException(PageHandlerExecutedContext context)
{ {
var wrapResultChecker = context.GetRequiredService<IWrapResultChecker>(); var wrapResultChecker = context.GetRequiredService<IWrapResultChecker>();
@ -84,5 +84,4 @@ namespace Sanhe.Abp.AspNetCore.Mvc.Wrapper.ExceptionHandling
context.Exception = null; //Handled! context.Exception = null; //Handled!
} }
}
} }

11
modules/mvc/Sanhe.Abp.AspNetCore.Mvc.Wrapper/Sanhe/Abp/AspNetCore/Mvc/Wrapper/ExceptionHandling/AbpExceptionWrapResultFilter.cs

@ -17,12 +17,12 @@ using Volo.Abp.ExceptionHandling;
using Volo.Abp.Http; using Volo.Abp.Http;
using Volo.Abp.Json; using Volo.Abp.Json;
namespace Sanhe.Abp.AspNetCore.Mvc.Wrapper.ExceptionHandling namespace Sanhe.Abp.AspNetCore.Mvc.Wrapper.ExceptionHandling;
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(AbpExceptionFilter))]
public class AbpExceptionWrapResultFilter : AbpExceptionFilter, ITransientDependency
{ {
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(AbpExceptionFilter))]
public class AbpExceptionWrapResultFilter : AbpExceptionFilter, ITransientDependency
{
protected async override Task HandleAndWrapException(ExceptionContext context) protected async override Task HandleAndWrapException(ExceptionContext context)
{ {
var wrapResultChecker = context.GetRequiredService<IWrapResultChecker>(); var wrapResultChecker = context.GetRequiredService<IWrapResultChecker>();
@ -86,5 +86,4 @@ namespace Sanhe.Abp.AspNetCore.Mvc.Wrapper.ExceptionHandling
context.Exception = null; //Handled! context.Exception = null; //Handled!
} }
}
} }

7
modules/mvc/Sanhe.Abp.AspNetCore.Mvc.Wrapper/Sanhe/Abp/AspNetCore/Mvc/Wrapper/Filters/AbpWrapResultFilter.cs

@ -6,10 +6,10 @@ using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace Sanhe.Abp.AspNetCore.Mvc.Wrapper.Filters namespace Sanhe.Abp.AspNetCore.Mvc.Wrapper.Filters;
public class AbpWrapResultFilter : IAsyncResultFilter, ITransientDependency
{ {
public class AbpWrapResultFilter : IAsyncResultFilter, ITransientDependency
{
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
{ {
if (ShouldWrapResult(context)) if (ShouldWrapResult(context))
@ -37,5 +37,4 @@ namespace Sanhe.Abp.AspNetCore.Mvc.Wrapper.Filters
return Task.CompletedTask; return Task.CompletedTask;
} }
}
} }

Loading…
Cancel
Save