cmd创建一个控制台应用程序

dotnet new console --name MyPipeline

用VSCode打开这个项目

新建类RequestDelegate.cs的类文件复制Program里面的代码到RequestDelegate里面代码修改

引入命名空间。

创建一个delegaet 叫做 RequestDelegate

为了演示用,新建一个Context.cs

完善RequestDelegate

新建一个List接收一个RequestDelegate返回一个Delegate

public static List<Func<RequestDelegate,RequestDelegate>> _list=new List<Func<RequestDelegate, RequestDelegate>>();

模拟我们的ApplicationBuilder里面的方法新建Use的方法,接受一个Func里面接受一个RequestDelegate返回一个RequestDelegate

  public static void Use(Func<RequestDelegate, RequestDelegate> middleware)
{
_list.Add(middleware);
}
using System;
using System.Collections.Generic;
using System.Threading.Tasks; namespace MyPipeline
{
class Program
{
public static List<Func<RequestDelegate,RequestDelegate>> _list=new List<Func<RequestDelegate, RequestDelegate>>();
static void Main(string[] args)
{
Use(next=>{
return context=>{
Console.WriteLine("");
return next.Invoke(context);
//return Task.CompletedTask;
};
});
Use(next=>{
return context=>{
Console.WriteLine("");
return next.Invoke(context);
};
}); RequestDelegate end= (context)=>{
Console.WriteLine("end.....");
return Task.CompletedTask;
};
_list.Reverse();//顺序反转
foreach(var middleware in _list)
{
end=middleware.Invoke(end);
} end.Invoke(new Context());
Console.ReadLine();
} public static void Use(Func<RequestDelegate, RequestDelegate> middleware)
{
_list.Add(middleware);
} }
}

Program.cs

dotnet run 执行

执行到1 没有再往下执行

以上就是整个Http管道的构成过程

最新文章

  1. Linux实战教学笔记03:操作系统发展历程及系统版本选择
  2. Redis安装及实现session共享
  3. JSP页面静态化
  4. 【android】Android am命令使用
  5. jQuery整体架构源码解析(转载)
  6. C#自旋的艺术
  7. Hadoop阅读笔记(六)——洞悉Hadoop序列化机制Writable
  8. datepicker冲突
  9. JS 显示时间与倒计时练习
  10. C#中如何设置窗体的默认按钮和取消按钮
  11. solr5.5教程-schema.xml部分配置
  12. github Top100
  13. Linux常用命令--网络管理篇(三)
  14. Windows Phone 8本地化多语言支持
  15. VK Cup 2017 - Round 1
  16. postgresql分析函数
  17. Elasticsearch之删除索引
  18. JavaScript——this
  19. 安装MongDB
  20. ubi 文件系统加载失败原因记录

热门文章

  1. OHIFViewer meteor build 问题
  2. 【转】Linux cp -a用法
  3. HDOJ 1217 Arbitrage(拟最短路,floyd算法)
  4. HTML URL编码规则
  5. JS 计算2个日期相差的天数
  6. 怎样搭建svn本地server,管理本地的代码
  7. Statelessness Provide credentials with the request. Each request MUST stand alone and should not be affected from previous conversation happened from same client in past.
  8. MFC上显示摄像头JPEG图片数据的两种方法
  9. DDD领域建模基本流程
  10. iOS开发UIScrollView常见属性和方法