From b30592b6aeb6de4256e593e82e5dc9c4fda17895 Mon Sep 17 00:00:00 2001
From: falcon <9504402@qq.com>
Date: Wed, 14 Sep 2022 15:01:32 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ASP.NET=20CORE=E4=B8=AD?=
=?UTF-8?q?=E9=97=B4=E4=BB=B6=E6=A8=A1=E6=9D=BF=E5=8F=8A=E5=9F=BA=E7=B1=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Middleware/MiddlewareBase.cs | 53 +++++++++++++++++++
1 file changed, 53 insertions(+)
create mode 100644 Falcon.SugarApi/ApiDefinistions/Middleware/MiddlewareBase.cs
diff --git a/Falcon.SugarApi/ApiDefinistions/Middleware/MiddlewareBase.cs b/Falcon.SugarApi/ApiDefinistions/Middleware/MiddlewareBase.cs
new file mode 100644
index 0000000..9db9458
--- /dev/null
+++ b/Falcon.SugarApi/ApiDefinistions/Middleware/MiddlewareBase.cs
@@ -0,0 +1,53 @@
+using Microsoft.AspNetCore.Http;
+using System.Threading.Tasks;
+
+namespace Falcon.SugarApi.ApiDefinistions.Middleware
+{
+ ///
+ /// ASP.NET CORE 中间件基类,模板类
+ ///
+ public abstract class MiddlewareBase
+ {
+ ///
+ /// 下一步请求
+ ///
+ private readonly RequestDelegate Next;
+
+ ///
+ /// 构造中间件
+ ///
+ /// 下一步
+ protected MiddlewareBase(RequestDelegate next) {
+ Next = next;
+ }
+
+ ///
+ /// 执行中间件
+ ///
+ /// HttpContext
+ /// 任务
+ public virtual async Task InvokeAsync(HttpContext context) {
+ await BeforeNext(context);
+ await this.Next(context);
+ await AfterNext(context);
+ }
+
+ ///
+ /// 在下一步之前执行的代码。由InvokeAsync调用
+ ///
+ /// HttpContext
+ /// 任务
+ public virtual async Task BeforeNext(HttpContext context) {
+ await Task.CompletedTask;
+ }
+
+ ///
+ /// 在下一步之后执行的代码。由InvokeAsync调用
+ ///
+ /// HttpContext
+ /// 任务
+ public virtual async Task AfterNext(HttpContext context) {
+ await Task.CompletedTask;
+ }
+ }
+}