1. 创建 Context.cs

using System;
using System.Threading.Tasks; namespace MyPipeline
{
public class Context{ }
}

2. 创建 RequestDelegate.cs

using System;
using System.Threading.Tasks; namespace MyPipeline
{
public delegate Task RequestDelegate(Context context);
}

3. 具体实现

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 => {
System.Console.WriteLine("");
return next.Invoke(context);
};
}); Use(next => {
return context => {
System.Console.WriteLine("");
return next.Invoke(context);
};
}); RequestDelegate end = (context) => {
System.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);
}
}
}

4. 运行结果


end ...

构建RequestDelegate管道的更多相关文章

  1. 【ASP.NET Core快速入门】(八)Middleware管道介绍、自己动手构建RequestDelegate管道

    中间件是汇集到以处理请求和响应的一个应用程序管道的软件. 每个组件: 可以选择是否要将请求传递到管道中的下一个组件. 之前和之后调用管道中的下一个组件,可以执行工作. 使用请求委托来生成请求管道. 请 ...

  2. 菜鸟入门【ASP.NET Core】8:Middleware管道介绍、自己动手构建RequestDelegate管道

    中间件:是汇集到以处理请求和响应的一个应用程序管道的软件. 每个组件: 可以选择是否要将请求传递到管道中的下一个组件. 之前和之后调用管道中的下一个组件,可以执行工作. 使用请求委托来生成请求管道.  ...

  3. 任务29:自己动手构建RequestDelegate管道

    cmd创建一个控制台应用程序 dotnet new console --name MyPipeline 用VSCode打开这个项目 新建类RequestDelegate.cs的类文件复制Program ...

  4. 29-自己动手构建RequestDelegate管道

    1-使用vsCode新建个项目 2-新建RequestDelegate和Context public delegate Task RequestDelegate(Context context); p ...

  5. .net core 2.0学习记录(四):Middleware使用以及模拟构建Middleware(RequestDelegate)管道

    .net Core中没有继续沿用以前asp.net中的管道事件,而是开发了一个新的管道(Middleware): public class MiddlewareDemo { private reado ...

  6. 任务28:RequestDelegate管道实现思路

    任务28:RequestDelegate管道实现思路 管道的实现机制 RequestDelegate是管道的核心.ApplicationBuilder就是接收了很多个RequestDelegae把它拼 ...

  7. Kafka笔记7(构建数据管道)

    构建数据管道需要考虑的问题: 及时性  可靠性 高吞吐量和动态吞吐量   数据格式  转换    安全性   故障处理能力  耦合性与灵活性 数据管道的构建分为2个阵营,ETL和ELT ETL:提取- ...

  8. ASP.NET Core Middleware管道介绍

    public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.Use(async (context, ne ...

  9. asp.net core WebAPI学习以及 发布(***入门学习)

    A asp.net Core 系列[一]——创建Web应用 asp.net Core 系列[二]—— 使用 ASP.NET Core 和 VS2017 for Windows 创建 Web API a ...

随机推荐

  1. Mint UI 之 Swipe 组件

    #为什么不显示内容? 一定要指定 mt-swipe 元素的宽和高. <mt-swipe :auto="4000" class="swipe"> &l ...

  2. 12月6日 被引入的jsp 页面,引入 js 要注意结束符 要用 </script> 而不是 />

    12月6日  被引入的jsp 页面,引入 js 要注意结束符 要用  </script> 而不是 />

  3. phalApi数据库操作

    在很多时候,我们会遇到数据库表里面的某个值需要+1操作,我们不能简单地在update的时候写入array('key' => 'key+1'),因为在解析sql的时候,key+1 会带上引号作为一 ...

  4. Java static说明

    class Person{ String name;//成员变量,实例变量 static String country = "CN";//静态变量.类变量 public void ...

  5. (KMP)Seek the Name, Seek the Fame -- poj --2752

    http://poj.org/problem?id=2752 Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536 ...

  6. hdu1081 To The Max 2016-09-11 10:06 29人阅读 评论(0) 收藏

    To The Max Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  7. php连接微软MSSQL(sql server)完全攻略

    http://www.jb51.net/article/98364.htm php连接微软MSSQL(sql server)完全攻略 作者:吵吵 字体:[增加 减小] 类型:转载 时间:2016-11 ...

  8. 【WinRT】让控件飞,WinRT 中实现 web 中的 dragable 效果

    由于在 xaml 体系中,控件没有传统 WebForm 中的 Left.Top.Right.Bottom 这些属性,取而代之的是按比例(像 Grid)等等的响应布局.但是,传统的这些设置 Left.T ...

  9. SpringBoot tomcat

    该文的前提是已经可以在控制台运行成功,有些时候想放在tomcat里运行 大致分为如下几步 1.配置文件更改 <dependency> <groupId>org.springfr ...

  10. python 模拟普通用户和管路员登录购物系统小程序

    程序功能描述如下:不同角色登录,普通用户可以查看商品购买商品.查看购物车和余额.退出:管理员可以充值,可以添加商品.退出 用户信息字典格式: { '', 'money': 14435.76, 'car ...