VOOZH about

URL: https://www.nuget.org/packages/NetPro.Web.Api/

⇱ NuGet Gallery | NetPro.Web.Api 6.0.16




👁 Image
NetPro.Web.Api 6.0.16

dotnet add package NetPro.Web.Api --version 6.0.16
 
 
NuGet\Install-Package NetPro.Web.Api -Version 6.0.16
 
 
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.Web.Api" Version="6.0.16" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NetPro.Web.Api" Version="6.0.16" />
 
Directory.Packages.props
<PackageReference Include="NetPro.Web.Api" />
 
Project file
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.Web.Api --version 6.0.16
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: NetPro.Web.Api, 6.0.16"
 
 
#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.Web.Api@6.0.16
 
 
#: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.Web.Api&version=6.0.16
 
Install as a Cake Addin
#tool nuget:?package=NetPro.Web.Api&version=6.0.16
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

NetPro.Web.Api使用

👁 NuGet

封装了基本asp.netcore webapi工程需要的基本功能

安装

  • Package Manager方式: Install-Package NetPro.Web.Api -Version 3.1.2

  • .NET CLI 方式: dotnet add package NetPro.Web.Api --version 3.1.2

  • PackageReference: <PackageReference Include="NetPro.Web.Api" Version="3.1.2" />

  • .NET CLI 方式: paket add NetPro.Web.Api --version 3.1.2


支持以下几种开发方式

1、简化版

API主程序集下每个业务模块一个文件夹隔离,业务模块下包含此业务模块的Controller、Service、Entity等等

2、程序集隔离

每个业务模块一个程序集,每个程序集中包含当前业务模块需要的所有Controller、Service、Entity等等,再API主程序集引用需要的业务模块,业务模块之间尽可能不互相依赖,引用。

3、插件方式

2、程序集隔离的基础上,API主程序集不直接引用需要的业务模块程序集,而是将各业务模块程序集放置在指定的插件文件夹中,插件路径配置如下:

"TypeFinderOption": {
		"MountePath": ""//windows默认目录: C:/opt/netpro ; linux环境:/opt/netpro
	},

注意

引用程序集会自动注入相关服务,无需再进行Service.Add..();

使用

appsetting.json
 //按需要配置以下节点,可忽略
 "NetProOption": {
		//"UseResponseCompression": false, //是否启用响应压缩		
		//"ApplicationName": "", //应用名称
		//"RequestWarningThreshold": 5, //请求时长的警告临界值
		//"RoutePrefix": "api" //全局路由前缀
 "IsDebug":true//Debug模式,默认true,方便线上调试
	},

内置中间件与系统中间件的映射关系:


public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
	
 app.UseExceptionHandler(); //对应ErrorHandlerStartup
 
	// your code
	...//此区间请求管道上的Order取值 范围0-100

 app.UseStaticFiles(); //对应StaticFilesStartup

	// your code
	...//此区间请求管道上的Order取值 范围101-200

 app.UseRouting(); //对应RoutingStartup

 // your code
	...//此区间请求管道上的Order取值 范围200-1000

 app.UseEndpoints(endpoints =>//对应EndpointsStartup
 {
 endpoints.MapRazorPages();
 });
}

考虑到灵活性,Netpro.Web.APi不包含UseEndpoints处理,如果不是通过脚手架生成NetPro项目,需要手动增加以下文件EndpointsStartup.cs到项目中

// <auto-generated>
// UseEndpoints 
// </auto-generated>

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace NetPro.Web.Api
{
 /// <summary>
 /// Endpoints 
 /// </summary>
 public class EndpointsStartup : INetProStartup
 {
 /// <summary>
 /// 
 /// </summary>
 /// <param name="services"></param>
 /// <param name="configuration"></param>
 /// <param name="typeFinder"></param>
 public void ConfigureServices(IServiceCollection services, IConfiguration configuration, TypeFinder.ITypeFinder typeFinder)
 {

 }

 /// <summary>
 /// 
 /// </summary>
 /// <param name="application"></param>
 public void Configure(IApplicationBuilder application)
 {
 application.UseEndpoints(s =>
 {
 s.MapControllers();//add other operation
 });
 }

 /// <summary>
 /// UseEndpoints should be loaded last
 /// </summary>
 public double Order { get; set; } = 1000;
 }
}

Feature

IWebHelper Web助手

包含获取客户端ip、是否GET POST,操作Query

使用:构造函数注入即可

 private readonly IWebHelper _webHelper;

 public XXXController(
 IWebHelper webHelper)
 {
 _webHelper = webHelper;
 }

_webHelper.GetCurrentIpAddress();

全局异常

包含全局异常处理 异常响应如下

System exception, please try again later

Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp3.1 netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.0.16 579 7/24/2023
6.0.15 1,441 7/19/2022
6.0.14 666 7/10/2022
6.0.13 716 6/15/2022
6.0.12 631 6/15/2022
6.0.11 579 6/15/2022
6.0.10 621 6/11/2022
6.0.9 604 6/8/2022
6.0.8 671 5/26/2022
6.0.8-beta.3 321 5/24/2022
6.0.8-beta.2 291 5/24/2022
6.0.7 603 5/18/2022
6.0.6 665 4/28/2022
6.0.5-beta.20 275 4/27/2022
6.0.5-beta.19 289 4/25/2022
6.0.5-beta.18 298 4/22/2022
6.0.5-beta.17 288 4/16/2022
6.0.5-beta.16 357 4/8/2022
6.0.5-beta.15 274 4/8/2022
6.0.5-beta.14 302 4/7/2022
Loading failed