NetPro.Proxy
6.0.3-beta.6
This is a prerelease version of NetPro.Proxy.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package NetPro.Proxy --version 6.0.3-beta.6
NuGet\Install-Package NetPro.Proxy -Version 6.0.3-beta.6
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NetPro.Proxy" Version="6.0.3-beta.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NetPro.Proxy" Version="6.0.3-beta.6" />
<PackageReference Include="NetPro.Proxy" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NetPro.Proxy --version 6.0.3-beta.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NetPro.Proxy, 6.0.3-beta.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NetPro.Proxy@6.0.3-beta.6
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NetPro.Proxy&version=6.0.3-beta.6&prerelease
#tool nuget:?package=NetPro.Proxy&version=6.0.3-beta.6&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
NetPro.Proxy使用
远程调用组件
使用
- 如果已添加环境变量ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=NetPro.Satrtup 启用自动初始化,添加appsetting.json 配置即可
appsetting.json
- 增加以下配置节点
"NetProProxyOption": {
"AssemblyPattern": "^XXX.*.Proxy$",//批量注入程序集的正则,此处表示将XXX开头,Proxy结尾的程序集中使用了NetProProxy功能的接口批量注入
"InterfacePattern": "^I.*.Proxy$", //I开头,Proxy结尾的接口
"IExampleProxy": "http://localhost:5000",//名称要与具体定义的接口名称一致,例如此项对应的接口定义为 public interface IExampleProxy{}
"IBaiduProxy": "http://baidu.com"
}
启用服务
如果没添加ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=NetPro.Satrtup环境变量,按以下方式注入服务,并添加上一条appsetting.json 节点配置即可
public void ConfigureServices(IServiceCollection services)
{
services.AddFileProcessService();
var typeFinder = services.BuildServiceProvider().GetRequiredService<ITypeFinder>();
services.AddHttpProxy(configuration, typeFinder, configuration.GetValue<string>("MicroServicesEndpoint:Assembly", string.Empty));
}
使用
定义服务
public interface IExampleProxy //命名对应appsetting.json 中的Example节点
{
[HttpGet("")]//HttpGet服务
[WebApiClientFilter]//服务过滤器
ITask<dynamic> GetAsync([Parameter(Kind.Query)]string account);
[HttpPost("api/v1/NetProgoods/list")]
[Timeout(10 * 1000)] // 10s超时
[WebApiClientFilter]
ITask<dynamic> GetGoodsList(int appid, string appVersion);
// POST api/user
[HttpPost("api/user")]
[WebApiClientFilter]
ITask<dynamic> AddAsync([FormContent] dynamic user);
/// <summary>
/// 登录
/// </summary>
/// <param name="username"></param>
/// <param name="password"></param>
/// <param name="Captcha"></param>
/// <returns></returns>
[HttpPost("/api/ldap")]
[Timeout(10 * 1000)] // 10s超时
[JsonReturn(Enable = false)]
[Cache(60 * 1000)]//接口缓存
[WebApiClientFilter]
ITask<dynamic> LoginByPwd([Uri] string url, [Parameter(Kind.Query)] string username, string password, string Captcha);
}
服务注入
public class HttpProxyController : ControllerBase
{
private readonly ILogger _logger;
private readonly IExampleProxy _exampleProxy;
//构造函数注入
public HttpProxyController(
ILogger<DatabaseCurdController> logger
IExampleProxy exampleProxy)
{
_logger = logger;
_exampleProxy = exampleProxy;
}
[HttpGet("getorcreate")]
[PostResponseCache(Duration = 2)]
[ProducesResponseType(200, Type = typeof(ResponseResult))]
public async Task<IActionResult> GetOrCreateAsync(uint id)
{
await _exampleProxy.AddAsync("");//直接使用定义的接口
return Ok();
}
}
使用过滤
复制以下代码放在请求方法顶部以特性方式使用,可实现方法的请求与响应的拦截处理,如需个性化处理,以此作为模板稍作改动即可
/// <summary>
/// 过滤器
/// </summary>
public class WebApiClientFilter : ApiFilterAttribute
{
/// <summary>
///
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override Task OnRequestAsync(ApiRequestContext context)
{
//请求开始前做的拦截
var uri= context.HttpContext.RequestMessage.RequestUri;
Console.WriteLine($"request uri is:{uri}");
return Task.CompletedTask;
}
/// <summary>
///
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override Task OnResponseAsync(ApiResponseContext context)
{
//对于响应做的拦截
Console.WriteLine($"HasResult:{context.ResultStatus}");
Console.WriteLine($"context.Result:{context.Result}");
var resultString = context.HttpContext.ResponseMessage.Content.ReadAsStringAsync().Result;
Console.WriteLine($"ReadAsStringAsync(): {resultString}");
Console.WriteLine($"StatusCode: {context.HttpContext.ResponseMessage.StatusCode}");
return Task.CompletedTask;
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- NetPro.Core (>= 6.0.3-beta.6)
- NetPro.TypeFinder (>= 6.0.3-beta.6)
- WebApiClientCore (>= 2.0.2)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on NetPro.Proxy:
| Package | Downloads |
|---|---|
|
NetPro.Web.Core
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 6.0.16 | 313 | 7/24/2023 |
| 6.0.15 | 535 | 7/19/2022 |
| 6.0.14 | 536 | 7/10/2022 |
| 6.0.13 | 548 | 6/15/2022 |
| 6.0.12 | 529 | 6/15/2022 |
| 6.0.11 | 510 | 6/15/2022 |
| 6.0.10 | 531 | 6/11/2022 |
| 6.0.9 | 552 | 6/8/2022 |
| 6.0.8 | 542 | 5/26/2022 |
| 6.0.8-beta.3 | 207 | 5/24/2022 |
| 6.0.8-beta.2 | 200 | 5/24/2022 |
| 6.0.7 | 554 | 5/18/2022 |
| 6.0.6 | 559 | 4/28/2022 |
| 6.0.5 | 538 | 3/30/2022 |
| 6.0.5-beta.20 | 213 | 4/27/2022 |
| 6.0.5-beta.19 | 213 | 4/25/2022 |
| 6.0.5-beta.18 | 218 | 4/22/2022 |
| 6.0.5-beta.17 | 208 | 4/16/2022 |
| 6.0.5-beta.16 | 217 | 4/8/2022 |
| 6.0.5-beta.15 | 213 | 4/8/2022 |
| 6.0.5-beta.14 | 224 | 4/7/2022 |
| 6.0.5-beta.13 | 219 | 4/7/2022 |
| 6.0.5-beta.12 | 213 | 4/6/2022 |
| 6.0.5-beta.11 | 212 | 4/6/2022 |
| 6.0.5-beta.10 | 216 | 3/31/2022 |
| 6.0.5-beta.9 | 227 | 3/26/2022 |
| 6.0.5-beta.8 | 220 | 3/22/2022 |
| 6.0.5-beta.7 | 219 | 3/21/2022 |
| 6.0.5-beta.6 | 222 | 3/14/2022 |
| 6.0.5-beta.5 | 218 | 3/2/2022 |
| 6.0.5-beta.4 | 228 | 2/22/2022 |
| 6.0.5-beta.3 | 219 | 2/18/2022 |
| 6.0.5-beta.2 | 219 | 2/18/2022 |
| 6.0.5-beta.1 | 223 | 2/16/2022 |
| 6.0.4 | 565 | 2/10/2022 |
| 6.0.3 | 529 | 2/9/2022 |
| 6.0.3-beta.9 | 221 | 2/10/2022 |
| 6.0.3-beta.7 | 253 | 1/27/2022 |
| 6.0.3-beta.6 | 254 | 1/19/2022 |
| 6.0.3-beta.5 | 248 | 1/17/2022 |
| 6.0.3-beta.4 | 245 | 1/16/2022 |
| 6.0.3-beta.3 | 249 | 1/13/2022 |
| 6.0.3-beta.2 | 277 | 1/11/2022 |
| 6.0.3-beta.1 | 265 | 1/11/2022 |
| 6.0.2 | 433 | 1/6/2022 |
| 6.0.1 | 1,101 | 12/3/2021 |
| 3.1.11 | 492 | 11/19/2021 |
| 3.1.10 | 565 | 7/29/2021 |
| 1.0.0 | 3,157 | 7/1/2021 |