当前位置:网站首页>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>();
}
}
边栏推荐
- Attack and defense world misc advanced area can_ has_ stdio?
- Serial port data frame
- PHP short video source code, thumb animation will float when you like it
- Microservices -- Opening
- Redis的持久化机制
- Unity vscode emmylua configuration error resolution
- Persistence mechanism of redis
- The sandbox has reached a cooperation with digital Hollywood to accelerate the economic development of creators through human resource development
- How to manage 15million employees easily?
- More than 30 institutions jointly launched the digital collection industry initiative. How will it move forward in the future?
猜你喜欢

Close system call analysis - Performance Optimization

2022-07-04:以下go语言代码输出什么?A:true;B:false;C:编译错误。 package main import “fmt“ func main() { fmt.Pri

质量体系建设之路的分分合合

Challenges faced by virtual human industry

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

新版判断PC和手机端代码,手机端跳转手机端,PC跳转PC端最新有效代码

SPSS installation and activation tutorial (including network disk link)

Serial port data frame

Detailed explanation of heap sort code

攻防世界 MISC 进阶区 Erik-Baleog-and-Olaf
随机推荐
MYSQL架构——用户权限与管理
Redis入门完整教程:客户端通信协议
Wake up day, how do I step by step towards the road of software testing
攻防世界 misc 进阶区 2017_Dating_in_Singapore
Shell 脚本实现应用服务日志入库 Mysql
Google Earth Engine(GEE)——以MODIS/006/MCD19A2为例批量下载逐天AOD数据逐天的均值、最大值、最小值、标准差、方差统计分析和CSV下载(北京市各区为例)
攻防世界 MISC 进阶区 Ditf
剑指Offer 68 - II. 二叉树的最近公共祖先
剑指 Offer 67. 把字符串转换成整数
Unity-VScode-Emmylua配置报错解决
Redis入门完整教程:发布订阅
Attack and defense world misc advanced zone 2017_ Dating_ in_ Singapore
Three stage operations in the attack and defense drill of the blue team
NFT insider 64: e-commerce giant eBay submitted an NFT related trademark application, and KPMG will invest $30million in Web3 and metauniverse
How to reset the password of MySQL root account
模拟摇杆控制舵机
关于栈区、堆区、全局区、文字常量区、程序代码区
Logo special training camp section III initial creative techniques
LOGO特训营 第二节 文字与图形的搭配关系
Short video system source code, click the blank space of the screen, the keyboard does not automatically stow