基类InvokeNextBefore和InvokeNextAfter方法改为virtual方法,这样子类不必重写所有两个方法

This commit is contained in:
falcon 2019-12-11 14:20:31 +08:00
parent a0f3d367f0
commit 86e03c09cf
2 changed files with 10 additions and 3 deletions

View File

@ -10,10 +10,17 @@ namespace Falcon.Middleware.Test
public MiddlewareTest(RequestDelegate next) : base(next) { public MiddlewareTest(RequestDelegate next) : base(next) {
} }
/// <summary>
/// 在调用next之后执行
/// </summary>
/// <param name="context">请求上下文</param>
public async override void InvokeNextAfter(HttpContext context) { public async override void InvokeNextAfter(HttpContext context) {
await context.Response.WriteAsync("\nInvokeNextAfter"); await context.Response.WriteAsync("\nInvokeNextAfter");
} }
/// <summary>
/// 在调用next之前执行
/// </summary>
/// <param name="context">请求上下文</param>
public async override void InvokeNextBefore(HttpContext context) { public async override void InvokeNextBefore(HttpContext context) {
await context.Response.WriteAsync("InvokeNextBefore\n"); await context.Response.WriteAsync("InvokeNextBefore\n");
} }

View File

@ -31,11 +31,11 @@ namespace Falcon.Middleware
/// 在执行下一个中间件之前执行 /// 在执行下一个中间件之前执行
/// </summary> /// </summary>
/// <param name="context">请求上下文</param> /// <param name="context">请求上下文</param>
public abstract void InvokeNextBefore(HttpContext context); public virtual void InvokeNextBefore(HttpContext context) { }
/// <summary> /// <summary>
/// 在执行下一个中间件之后执行 /// 在执行下一个中间件之后执行
/// </summary> /// </summary>
/// <param name="context">请求上下文</param> /// <param name="context">请求上下文</param>
public abstract void InvokeNextAfter(HttpContext context); public virtual void InvokeNextAfter(HttpContext context) { }
} }
} }