diff --git a/aspnet-core/framework/common/LINGYUN.Abp.Http.Client.Wrapper/README.EN.md b/aspnet-core/framework/common/LINGYUN.Abp.Http.Client.Wrapper/README.EN.md new file mode 100644 index 000000000..5830516f3 --- /dev/null +++ b/aspnet-core/framework/common/LINGYUN.Abp.Http.Client.Wrapper/README.EN.md @@ -0,0 +1,45 @@ +# LINGYUN.Abp.Http.Client.Wrapper + +HTTP client wrapper module for automatically adding wrapper request headers in HTTP client requests. + +[简体中文](./README.md) + +## Features + +* Automatic addition of wrapper request headers +* Integration with ABP HTTP client +* Support for global wrapper configuration + +## Installation + +```bash +dotnet add package LINGYUN.Abp.Http.Client.Wrapper +``` + +## Configuration + +```csharp +[DependsOn(typeof(AbpHttpClientWrapperModule))] +public class YouProjectModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + // Enable wrapper + options.IsEnabled = true; + }); + } +} +``` + +## How It Works + +When the wrapper is enabled (`AbpWrapperOptions.IsEnabled = true`), the module automatically adds the `_AbpWrapResult` header to all HTTP client requests. +When the wrapper is disabled (`AbpWrapperOptions.IsEnabled = false`), the module automatically adds the `_AbpDontWrapResult` header to all HTTP client requests. + +This ensures that the HTTP client request results remain consistent with the server-side wrapper configuration. + +## Source Code + +[LINGYUN.Abp.Http.Client.Wrapper](https://github.com/colinin/abp-next-admin/tree/master/aspnet-core/framework/common/LINGYUN.Abp.Http.Client.Wrapper) diff --git a/aspnet-core/framework/common/LINGYUN.Abp.Http.Client.Wrapper/README.md b/aspnet-core/framework/common/LINGYUN.Abp.Http.Client.Wrapper/README.md new file mode 100644 index 000000000..4d8b8c220 --- /dev/null +++ b/aspnet-core/framework/common/LINGYUN.Abp.Http.Client.Wrapper/README.md @@ -0,0 +1,45 @@ +# LINGYUN.Abp.Http.Client.Wrapper + +HTTP客户端包装器模块,用于在HTTP客户端请求中自动添加包装器请求头。 + +[English](./README.EN.md) + +## 功能特性 + +* 自动添加包装器请求头 +* 与ABP HTTP客户端集成 +* 支持全局配置包装器开关 + +## 安装 + +```bash +dotnet add package LINGYUN.Abp.Http.Client.Wrapper +``` + +## 配置使用 + +```csharp +[DependsOn(typeof(AbpHttpClientWrapperModule))] +public class YouProjectModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + // 启用包装器 + options.IsEnabled = true; + }); + } +} +``` + +## 工作原理 + +当启用包装器时(`AbpWrapperOptions.IsEnabled = true`),模块会自动为所有HTTP客户端请求添加 `_AbpWrapResult` 请求头。 +当禁用包装器时(`AbpWrapperOptions.IsEnabled = false`),模块会自动为所有HTTP客户端请求添加 `_AbpDontWrapResult` 请求头。 + +这样可以确保HTTP客户端的请求结果与服务器端的包装配置保持一致。 + +## 源码位置 + +[LINGYUN.Abp.Http.Client.Wrapper](https://github.com/colinin/abp-next-admin/tree/master/aspnet-core/framework/common/LINGYUN.Abp.Http.Client.Wrapper) diff --git a/aspnet-core/framework/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/README.EN.md b/aspnet-core/framework/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/README.EN.md new file mode 100644 index 000000000..b7629367d --- /dev/null +++ b/aspnet-core/framework/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/README.EN.md @@ -0,0 +1,98 @@ +# LINGYUN.Abp.AspNetCore.Mvc.Wrapper + +MVC wrapper implementation module for unified wrapping of ASP.NET Core MVC response results. + +[简体中文](./README.md) + +## Features + +* Automatic wrapping of MVC response results +* Support for custom wrapping rules +* Support for exception result wrapping +* Support for localized error messages +* Support for API documentation wrapping description +* Support for ignoring specific controllers, namespaces, and return types + +## Installation + +```bash +dotnet add package LINGYUN.Abp.AspNetCore.Mvc.Wrapper +``` + +## Configuration + +```csharp +[DependsOn(typeof(AbpAspNetCoreMvcWrapperModule))] +public class YouProjectModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + // Enable wrapper + options.IsEnabled = true; + + // Ignore specific return types + options.IgnoreReturnTypes.Add(); + + // Ignore specific controllers + options.IgnoreControllers.Add(); + + // Ignore specific URL prefixes + options.IgnorePrefixUrls.Add("/connect"); + + // Custom empty result message + options.MessageWithEmptyResult = (serviceProvider) => + { + var localizer = serviceProvider.GetRequiredService>(); + return localizer["Wrapper:NotFound"]; + }; + }); + } +} +``` + +## Configuration Options + +* `IsEnabled`: Whether to enable the wrapper +* `IsWrapUnauthorizedEnabled`: Whether to wrap unauthorized responses +* `HttpStatusCode`: HTTP status code for wrapped responses +* `IgnoreReturnTypes`: List of return types to ignore wrapping +* `IgnoreControllers`: List of controllers to ignore wrapping +* `IgnoreNamespaces`: List of namespaces to ignore wrapping +* `IgnorePrefixUrls`: List of URL prefixes to ignore wrapping +* `IgnoreExceptions`: List of exception types to ignore wrapping +* `ErrorWithEmptyResult`: Whether to return error message for empty results +* `CodeWithEmptyResult`: Error code for empty results +* `MessageWithEmptyResult`: Error message for empty results +* `CodeWithSuccess`: Code for successful responses + +## Advanced Usage + +### 1. Using Attributes to Ignore Wrapping + +```csharp +[IgnoreWrapResult] +public class TestController : AbpController +{ + // All actions in this controller will not be wrapped +} + +public class TestController : AbpController +{ + [IgnoreWrapResult] + public IActionResult Test() + { + // This action will not be wrapped + } +} +``` + +### 2. Controlling Wrapping via Request Headers + +* Add `_AbpDontWrapResult` header to disable wrapping +* Add `_AbpWrapResult` header to force enable wrapping + +## Source Code + +[LINGYUN.Abp.AspNetCore.Mvc.Wrapper](https://github.com/colinin/abp-next-admin/tree/master/aspnet-core/framework/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper) diff --git a/aspnet-core/framework/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/README.md b/aspnet-core/framework/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/README.md index cb82af1be..0e3c472a4 100644 --- a/aspnet-core/framework/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/README.md +++ b/aspnet-core/framework/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper/README.md @@ -1,6 +1,23 @@ # LINGYUN.Abp.AspNetCore.Mvc.Wrapper -包装器 MVC 实现模块 +包装器 MVC 实现模块,用于统一包装ASP.NET Core MVC的响应结果。 + +[English](./README.EN.md) + +## 功能特性 + +* 自动包装MVC响应结果 +* 支持自定义包装规则 +* 支持异常结果包装 +* 支持本地化错误消息 +* 支持API文档包装描述 +* 支持忽略特定控制器、命名空间、返回类型的包装 + +## 安装 + +```bash +dotnet add package LINGYUN.Abp.AspNetCore.Mvc.Wrapper +``` ## 配置使用 @@ -8,17 +25,74 @@ [DependsOn(typeof(AbpAspNetCoreMvcWrapperModule))] public class YouProjectModule : AbpModule { - public override void ConfigureServices(ServiceConfigurationContext context) - { - Configure(options => - { - // 启用包装器 - options.IsEnabled = true; + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + // 启用包装器 + options.IsEnabled = true; + + // 忽略特定返回类型 + options.IgnoreReturnTypes.Add(); + + // 忽略特定控制器 + options.IgnoreControllers.Add(); + + // 忽略特定URL前缀 + options.IgnorePrefixUrls.Add("/connect"); + + // 自定义空结果消息 + options.MessageWithEmptyResult = (serviceProvider) => + { + var localizer = serviceProvider.GetRequiredService>(); + return localizer["Wrapper:NotFound"]; + }; }); - } + } } ``` + ## 配置项说明 -## 其他 +* `IsEnabled`: 是否启用包装器 +* `IsWrapUnauthorizedEnabled`: 是否包装未授权响应 +* `HttpStatusCode`: 包装响应的HTTP状态码 +* `IgnoreReturnTypes`: 忽略包装的返回类型列表 +* `IgnoreControllers`: 忽略包装的控制器列表 +* `IgnoreNamespaces`: 忽略包装的命名空间列表 +* `IgnorePrefixUrls`: 忽略包装的URL前缀列表 +* `IgnoreExceptions`: 忽略包装的异常类型列表 +* `ErrorWithEmptyResult`: 空结果是否返回错误信息 +* `CodeWithEmptyResult`: 空结果的错误代码 +* `MessageWithEmptyResult`: 空结果的错误消息 +* `CodeWithSuccess`: 成功时的代码 + +## 高级用法 + +### 1. 使用特性标记忽略包装 + +```csharp +[IgnoreWrapResult] +public class TestController : AbpController +{ + // 该控制器下所有Action都不会被包装 +} + +public class TestController : AbpController +{ + [IgnoreWrapResult] + public IActionResult Test() + { + // 该Action不会被包装 + } +} +``` + +### 2. 通过请求头控制包装 + +* 添加 `_AbpDontWrapResult` 请求头可以禁用包装 +* 添加 `_AbpWrapResult` 请求头可以强制启用包装 + +## 源码位置 +[LINGYUN.Abp.AspNetCore.Mvc.Wrapper](https://github.com/colinin/abp-next-admin/tree/master/aspnet-core/framework/mvc/LINGYUN.Abp.AspNetCore.Mvc.Wrapper)