All Projects → LeonKou → Netpro

LeonKou / Netpro

🌈An enhanced version of asp.netcore,Support for netcore3.1

Projects that are alternatives of or similar to Netpro

Butterfly
🔥 蝴蝶--【简单】【稳定】【好用】的 Python web 框架🦋 除 Python 2.7,无其他依赖; 🦋 butterfly 是一个 RPC 风格 web 框架,同时也是微服务框架,自带消息队列通信机制实现分布式
Stars: ✭ 82 (-26.79%)
Mutual labels:  microservice, redis, mq
Filterlists
🛡 The independent, comprehensive directory of filter and host lists for advertisements, trackers, malware, and annoyances.
Stars: ✭ 653 (+483.04%)
Mutual labels:  automapper, redis, docker-compose
Aaframework
AA.Framework is built on the popular open source class library of NET Core
Stars: ✭ 128 (+14.29%)
Mutual labels:  automapper, redis, dapper
Abp Asp.net Boilerplate Project Cms
ABP module-zero +AdminLTE+Bootstrap Table+jQuery+Redis + sql server+quartz+hangfire权限管理系统
Stars: ✭ 677 (+504.46%)
Mutual labels:  webapi, automapper, redis
Jiiiiiin Security
一个前后端分离的内管基础项目
Stars: ✭ 132 (+17.86%)
Mutual labels:  microservice, apollo, redis
User.api
集成网关、身份认证、Token授权、微服务、.netcore等的基于CQRS的微服务开发框架示例
Stars: ✭ 109 (-2.68%)
Mutual labels:  webapi, redis, docker-compose
Docker Superset
Repository for Docker Image of Apache-Superset. [Docker Image: https://hub.docker.com/r/abhioncbr/docker-superset]
Stars: ✭ 86 (-23.21%)
Mutual labels:  redis, docker-compose
Mechanist
[Docker] - The Mechanist is a collection of Dockerfiles and Composefiles for various tools and purposes.
Stars: ✭ 86 (-23.21%)
Mutual labels:  redis, docker-compose
Docker Django Example
A production ready example Django app that's using Docker and Docker Compose.
Stars: ✭ 86 (-23.21%)
Mutual labels:  redis, docker-compose
Quell
Quell is an easy-to-use, lightweight JavaScript library providing a client- and server-side caching solution for GraphQL. Use Quell to prevent redundant client-side API requests and to minimize costly server-side response latency.
Stars: ✭ 90 (-19.64%)
Mutual labels:  apollo, redis
Graphql Microservices
Showcasing a graphql microservice setup
Stars: ✭ 68 (-39.29%)
Mutual labels:  microservice, docker-compose
Aspnetcore Ddd
Full ASP.NET Core 3.1 LTS application with DDD, CQRS and Event Sourcing
Stars: ✭ 88 (-21.43%)
Mutual labels:  webapi, automapper
Sci Pype
A Machine Learning API with native redis caching and export + import using S3. Analyze entire datasets using an API for building, training, testing, analyzing, extracting, importing, and archiving. This repository can run from a docker container or from the repository.
Stars: ✭ 90 (-19.64%)
Mutual labels:  redis, docker-compose
Web Development Interview With Java
Java 开发相关技术栈(大中厂)高频面试问题收录。
Stars: ✭ 69 (-38.39%)
Mutual labels:  microservice, redis
Slickone
A Quick Enterprise Web Framework for Information System 企业级Web快速开发框架
Stars: ✭ 87 (-22.32%)
Mutual labels:  webapi, dapper
Event Sourcing Castanha
An Event Sourcing service template with DDD, TDD and SOLID. It has High Cohesion and Loose Coupling, it's a good start for your next Microservice application.
Stars: ✭ 68 (-39.29%)
Mutual labels:  microservice, webapi
Docker For All
Docker applied in development, devops, testing, product management etc.
Stars: ✭ 88 (-21.43%)
Mutual labels:  microservice, docker-compose
Docker Laravel
🐳 Docker Images for Laravel development
Stars: ✭ 101 (-9.82%)
Mutual labels:  redis, docker-compose
Python Microservice Fastapi
Learn to build your own microservice using Python and FastAPI
Stars: ✭ 96 (-14.29%)
Mutual labels:  microservice, docker-compose
Spring Boot 2.x Examples
Spring Boot 2.x code examples
Stars: ✭ 104 (-7.14%)
Mutual labels:  redis, mq

NetPro

.NET Core NuGet

🕰️ 项目请参照

简要

NetPro项目封装常用组件和初始配置,为快速开发webapi,守护进程,windwos服务提供基础模板,支持.NetCore3.1,支持.Net5 Preview

主要组件:

FreeSql,Autofac , Automapper,apollo,App.Metrics,

CsRedisCore,StackExchange.Redis,Serilog,

MiniProfiler,FluentValidation,IdGen,

MongoDb,Dapper,RedLock.Net,

Sentry,RabbitMQ.Client,SkyAPM,

Swagger,WebApiClient.Core,

TimeZoneConverter,healthcheck

exceptionless

使用

NetPro.Web.Api组件打包封装了其他所有组件,"开箱即用",各组件已发布Nuget包,也可单独使用,建议直接使用NetPro.Web.Api省去各种初始化与避免配置有误导致的问题
包含的内置组件

具体参考sample/Leon.XXX.Api(分层)项目

  • webapi项目引用 NetPro.Web.Api NuGet 引用最新nuget即可

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

  • 修改Program.cs
public class Program
{
/// <summary>
/// 
/// </summary>
/// <param name="args"></param>
public static void Main(string[] args)
{
	CreateHostBuilder(args).Build().Run();
}

/// <summary>
/// 
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public static IHostBuilder CreateHostBuilder(string[] args) =>
	Host.CreateDefaultBuilder(args)
	.UseServiceProviderFactory(new AutofacServiceProviderFactory())
	.ConfigureAppConfiguration((hostingContext, config) => ApolloClientHelper.ApolloConfi	(hostingContext, config, args))
	.ConfigureWebHostDefaults(webBuilder =>
	{
		webBuilder.UseStartup<Startup>();
	}).UseSerilog();
	}
  • 修改 Startup.cs
public class Startup
{
 #region Fields

 private readonly IConfiguration _configuration;
 private readonly IWebHostEnvironment _webHostEnvironment;
 private IEngine _engine;
 private NetProOtion _NetProOtion;

 #endregion

 #region Ctor

 /// <summary>
 /// 
 /// </summary>
 /// <param name="configuration"></param>
 /// <param name="webHostEnvironment"></param>
 public Startup(IConfiguration configuration, IWebHostEnvironment webHostEnvironment)
 {
 	_configuration = configuration;
 	_webHostEnvironment = webHostEnvironment;
 }

 #endregion

 // This method gets called by the runtime. Use this method to add services to the  container.
 /// <summary>
 /// 
 /// </summary>
 /// <param name="services"></param>
 public void ConfigureServices(IServiceCollection services)
 {
 	(_engine, _NetProOtion) = services.ConfigureApplicationServices(_configuration, _webHostEnvironment);
 }

 /// <summary>
 /// 
 /// </summary>
 /// <param name="builder"></param>
 public void ConfigureContainer(ContainerBuilder builder)
 {
 	_engine.RegisterDependencies(builder, _NetProOtion);
 }
 
 // This method gets called by the runtime. Use this method to configure the HTTP request  pipeline.
 /// <summary>
 /// 
 /// </summary>
 /// <param name="app"></param>
 /// <param name="env"></param>
 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
 {
 	app.ConfigureRequestPipeline();
 }
}
  • 为了Startup文件干净清爽,建议创建ApiStartup.cs文件

此文件继承INetProStartup接口,提供了microsoft原生依赖注入能力,所有组件注入放于此 ,Startup.cs将不接受组件注入

  • 修改appsettings.json 文件

{	
	//数据库ORM建议使用FreeSql,为了便于灵活选择使用适合自己的ORM,框架已剔除内置的NetPro.Dapper
	//apollo配置
	"Apollo": {
		"Enabled": false,
		"AppId": "Leon",
		"MetaServer": "http://192.168.56.98:7078",
		"Cluster": "default",
		"Namespaces": "AppSetting,MicroServicesEndpoint",
		"RefreshInterval": 300000,
		"LocalCacheDir": "apollo/data"
	},
	//响应缓存配置,建议不大于3
	"ResponseCacheOption": {
		"Enabled": true,
		"Duration": 3,
		"IgnoreVaryQuery": [ "sign", "timestamp" ]
	},
	//日志配置
	"Serilog": {
		"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.Async", "Serilog.Sinks.File" ],
		"MinimumLevel": {
			"Default": "Information",
			"Override": {
				"Microsoft": "Debug",
				"System": "Debug",
				"System.Net.Http.HttpClient": "Debug"
			}
		},
		"WriteTo:Async": {
			"Name": "Async",
			"Args": {
				"configure": [
					{ "Name": "Console" }
				]
			}
		},
		"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
		"Properties": {
			"Application": "Netpro"
		}
	},

	"AllowedHosts": "*",
	//框架核心配置
	"NetProOption": {
		"ProjectPrefix": "Leon",
		"ProjectSuffix": "",
		"UseResponseCompression": false,
		"ThreadMinCount": 5,
		"ApplicationName": "",
		"RequestWarningThreshold": 5
	},
	//接口签名防篡改配置
	"VerifySignOption": {		
		"Enable": true,
		"IsDarkTheme":true,
		"IsDebug": false,
		"IsForce": false, //是否强制签名
		"Scheme": "attribute", //attribute;global
		"ExpireSeconds": 60,
		"CommonParameters": {
			"TimestampName": "timestamp",
			"AppIdName": "appid",
			"SignName": "sign"
		},
		"AppSecret": {
			"AppId": {
				"sadfsdf": "sdfsfd"
			}
		},
		"IgnoreRoute": [ "api/ignore/", "" ]
	},
	//swagger配置
	"SwaggerOption": {
		"Enable": true,
		"IsDarkTheme":true,//Swagger黑色主题
		"MiniProfilerEnabled": false,
		"XmlComments": [ "", "" ],
		"RoutePrefix": "swagger",
		"Description": "this is swagger for netcore",
		"Title": "Demo swagger",
		"Version": "first version",
		"TermsOfService": "netcore.com",
		"Contact": {
			"Email": "[email protected]",
			"Name": "swagger",
			"Url": "[email protected]"
		},
		"License": {
			"Name": "",
			"Url": ""
		},
		"Headers": [ //swagger默认公共头参数
			{
				"Name": "User",
				"Description": "用户"
			}
		], 
		"Query": [ //swagger默认url公共参数
			{
				"Name": "sign",
				"Description": "签名"
			},
			{
				"Name": "timestamp",
				"Description": "客户端时间戳"
			}
		]
	},
	//中间件健康检查配置
	"HealthChecksUI": {
		"HealthChecks": [
			{
				"Name": "HealthList",
				"Uri": "/health"
			}
		],
		"Webhooks": [],
		"EvaluationTimeOnSeconds": 3600, //检查周期,单位秒
		"MinimumSecondsBetweenFailureNotifications": 60
	},

	"Hosting": {
		"ForwardedHttpHeader": "",
		"UseHttpClusterHttps": false,
		"UseHttpXForwardedProto": false
	},
	//redis配置
	"RedisCacheOption": {
		"Enabled": true,
		"RedisComponent": 1,
		"Password": "netpro",
		"IsSsl": false,
		"Preheat": 20,
		"Cluster": true, //集群模式
		"ConnectionTimeout": 20,
		"Endpoints": [
			{
				"Port": 6379,
				"Host": "192.168.7.66"
			}
		],
		"Database": 0,
		"DefaultCustomKey": "NetPro:",//key前缀
		"PoolSize": 50
	},
	//跨服务访问配置
	"MicroServicesEndpoint": {
		"Example": "http://localhost:5000",
		"Baidu": ""
	},
	//mongodb配置
	"MongoDbOptions": {
		"Enabled": false,
		"ConnectionString": null,
		"Database": -1
	},
	//rabbitmq配置
	"RabbitMq": {
		"HostName": "127.0.0.1",
		"Port": "5672",
		"UserName": "guest",
		"Password": "guest"
	},
	"RabbitMqExchange": {
		"Type": "direct",
		"Durable": true,
		"AutoDelete": false,
		"DeadLetterExchange": "default.dlx.exchange",
		"RequeueFailedMessages": true,
		"Queues": [
			{
				"Name": "myqueue",
				"RoutingKeys": [ "routing.key" ]
			}
		]
	}
}


  • Controller使用

Controller继承ApiControllerBase抽象类提供统一响应和简化其他操作,如果不需要默认提供的响应格式也可直接继承ControllerBase

	/// <summary>
	///
	/// </summary>
	[Route("api/v1/[controller]")]
	public class WeatherForecastController : ApiControllerBase
	{
		private readonly ILogger _logger;
		private IExampleProxy _userApi { get; set; }

		public WeatherForecastController(ILogger logger
			 ,IExampleProxy userApi)
		{
			_logger = logger;
			_userApi = userApi;
		}
	}

约定

以下后缀结尾的类将自动DI注入
  • Service 业务相关
  • Repository 数据仓储相关(需要直接在Service或Controller中直接操作数据库可无需使用此后缀)
  • Proxy 代理请求相关(请求远程接口使用)
  • Aggregate 聚合相关,当Service 或者Controller 业务逻辑繁琐复杂可在此聚合后再调用

发布

发布自包含应用
dotnet publish -r linux-x64 -c release /p:PublishSingleFile=true /p:PublishTrimmed=true
依赖CLR运行时应用
dotnet publish -r linux-x64 -c release

运行

开发环境运行后效果如下:


          ____  _____        _   _______
        |_   \|_   _|      / |_|_   __ \
          |   \ | |  .---.`| |-' | |__) |_ .--.   .--.
          | |\ \| | / /__\\| |   |  ___/[ `/'`\]/ .'`\ \
         _| |_\   |_| \__.,| |, _| |_    | |    | \__. |
        |_____|\____|'.__.'\__/|_____|  [___]    '.__.'


[20:20:34 Development] dotnet process id:349824
服务注入顺序:
+-------+------------------------+-------------------------------------------------------+
| Order | StartUpName            | Path                                                  |
+-------+------------------------+-------------------------------------------------------+
| 0     | ErrorHandlerStartup    | NetPro.Web.Core.Infrastructure.ErrorHandlerStartup    |
+-------+------------------------+-------------------------------------------------------+
| 100   | NetProCommonStartup    | NetPro.Web.Core.Infrastructure.NetProCommonStartup    |
+-------+------------------------+-------------------------------------------------------+
| 100   | NetProRateLimitStartup | NetPro.Web.Core.Infrastructure.NetProRateLimitStartup |
+-------+------------------------+-------------------------------------------------------+
| 105   | ShareBodyStartup101    | NetPro.Web.Core.Infrastructure.ShareBodyStartup101    |
+-------+------------------------+-------------------------------------------------------+
| 110   | SignStartup            | NetPro.Web.Core.Infrastructure.SignStartup            |
+-------+------------------------+-------------------------------------------------------+
| 115   | ResponseCacheStartup   | NetPro.Web.Core.Infrastructure.ResponseCacheStartup   |
+-------+------------------------+-------------------------------------------------------+
| 120   | NetProApiStartup       | NetPro.Web.Api.NetProApiStartup                       |
+-------+------------------------+-------------------------------------------------------+
| 500   | AuthenticationStartup  | NetPro.Web.Core.Infrastructure.AuthenticationStartup  |
+-------+------------------------+-------------------------------------------------------+
| 900   | ApiStartup             | Leon.XXX.Api.ApiStartup                               |
+-------+------------------------+-------------------------------------------------------+
| 900   | XXXApiProxyStartup     | Leon.XXX.Proxy.XXXApiProxyStartup                     |
+-------+------------------------+-------------------------------------------------------+
| 1000  | NetProCoreStartup      | NetPro.Web.Core.Infrastructure.NetProCoreStartup      |
+-------+------------------------+-------------------------------------------------------+
| 2000  | ApiProxyStartup        | NetPro.Web.Api.ApiProxyStartup                        |
+-------+------------------------+-------------------------------------------------------+

核心数为:8--默认线程最小为:40--Available:32767
[20:20:51 DBG] Hosting starting
[20:20:51 DBG] Failed to locate the development https certificate at 'null'.
[20:20:51 INF] Now listening on: http://localhost:5001
[20:20:51 DBG] Loaded hosting startup assembly Leon.XXX.Api
[20:20:51 INF] Application started. Press Ctrl+C to shut down.
[20:20:51 INF] Hosting environment: Development
[20:20:51 INF] Content root path: G:\vsFile\netproFile\NetPro\src\sample\Leon.XXX.Api
[20:20:51 DBG] Hosting started

Swagger地址:/swagger/index.html

健康检查地址 /health

健康检查面板/ui

应用信息 /info

环境信息 /env

问题汇总

1. 如何覆盖系统异常处理

var mvcBuilder = services.AddControllers(config =>
   {
    config.Filters.Add(typeof(CustomerExceptionFilter),2);//自定义全局异常过滤器//100是order值,越大越靠后加载
});

...

Target

...

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].