当前位置:网站首页>Talk about Middleware
Talk about Middleware
2022-07-04 22:50:00 【InfoQ】
First, let's talk about the basic concepts
Let's take another look at a real case
public class TestMiddleware1
{
private readonly RequestDelegate _next;
public TestMiddleware1(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext context)
{
AnsiConsole.MarkupLine($"[red] I am the first 1 Middleware , I'm coming -{DateTime.Now}[/]");
await _next(context);
AnsiConsole.MarkupLine($"[red] I am the first 1 Middleware , I stepped down -{DateTime.Now}[/]");
}
}
public static class TestMiddlewareExtensions
{
public static void UseTest(this WebApplication app)
{
app.UseMiddleware<TestMiddleware1>();
}
}
var app = builder.Build();
... Other middleware
app.UseTest();
var app = builder.Build();
app.UseTest();
app.Use(async (context, next) =>
{
AnsiConsole.MarkupLine($"[Yellow] I am the first 2 Middleware , I come from the entry file , I'm coming -{DateTime.Now}[/]");
await next(context);
AnsiConsole.MarkupLine($"[Yellow] I am the first 2 Middleware , I come from the entry file , I stepped down -{DateTime.Now}[/]");
});
public class TestMiddleware1
{
private readonly RequestDelegate _next;
public TestMiddleware1(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext context)
{
AnsiConsole.MarkupLine($"[red] I am the first 1 Middleware , I'm coming -{DateTime.Now}[/]");
await _next(context);
AnsiConsole.MarkupLine($"[red] I am the first 1 Middleware , I stepped down -{DateTime.Now}[/]");
}
}
public class TestMiddleware2
{
private readonly RequestDelegate _next;
public TestMiddleware2(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext context)
{
AnsiConsole.MarkupLine($"[green] I am the first 2 Middleware , I'm coming -{DateTime.Now}[/]");
await _next(context);
AnsiConsole.MarkupLine($"[green] I am the first 2 Middleware , I stepped down -{DateTime.Now}[/]");
}
}
public class TestMiddleware3
{
private readonly RequestDelegate _next;
public TestMiddleware3(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext context)
{
AnsiConsole.MarkupLine($"[blue] I am the first 3 Middleware , I'm coming -{DateTime.Now}[/]");
await _next(context);
AnsiConsole.MarkupLine($"[blue] I am the first 3 Middleware , I stepped down -{DateTime.Now}[/]");
}
}
public static class TestMiddlewareExtensions
{
public static void UseTest(this WebApplication app)
{
app.UseMiddleware<TestMiddleware1>();
app.UseMiddleware<TestMiddleware2>();
app.UseMiddleware<TestMiddleware3>();
}
}
边栏推荐
- La prospérité est épuisée, les choses sont bonnes et mauvaises: Où puis - je aller pour un chef de station personnel?
- Unity-VScode-Emmylua配置报错解决
- Mysql root 账号如何重置密码
- More than 30 institutions jointly launched the digital collection industry initiative. How will it move forward in the future?
- LOGO特训营 第五节 字体结构与设计常用技法
- Postgresqlql advanced skills pivot table
- Google Earth engine (GEE) -- take modis/006/mcd19a2 as an example to batch download the daily mean, maximum, minimum, standard deviation, statistical analysis of variance and CSV download of daily AOD
- 华泰证券是国家认可的券商吗?开户安不安全?
- Breakpoint debugging under vs2019 c release
- 9 - 类
猜你喜欢
共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf
都说软件测试很简单有手就行,但为何仍有这么多劝退的?
Logo special training camp Section V font structure and common design techniques
Advanced area of attack and defense world misc 3-11
攻防世界 MISC 进阶区 hit-the-core
10 schemes to ensure interface data security
常用技术指标之一文读懂BOLL布林线指标
Logo special training camp Section IV importance of font design
Attack and defense world misc advanced area Hong
Introducing QA into the software development lifecycle is the best practice that engineers should follow
随机推荐
The new version judges the code of PC and mobile terminal, the mobile terminal jumps to the mobile terminal, and the PC jumps to the latest valid code of PC terminal
Analog rocker controlled steering gear
Li Kou 98: verify binary search tree
Concurrent network modular reading notes transfer
About stack area, heap area, global area, text constant area and program code area
关于栈区、堆区、全局区、文字常量区、程序代码区
SPSS安装激活教程(包含网盘链接)
攻防世界 MISC 进阶 glance-50
Tla+ introductory tutorial (1): introduction to formal methods
攻防世界 MISC 进阶区 hit-the-core
【lua】int64的支持
LOGO特训营 第二节 文字与图形的搭配关系
String类中的常用方法
Attack and defense world misc advanced grace-50
The overview and definition of clusters can be seen at a glance
Hit the core in the advanced area of misc in the attack and defense world
Shell 脚本实现应用服务日志入库 Mysql
Introduction and application of bigfilter global transaction anti duplication component
Business is too busy. Is there really no reason to have time for automation?
Gnawing down the big bone - sorting (II)