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. DefaultSingletonBeanRegistry

    DefaultSingletonBeanRegistry 这是 DefaultSingletonBeanRegistry 类的体系结构,由一个类一个责任的原则: AliasRegistry : 提供别 ...

  2. springmvc 返回汉字乱码

    1.删除配置文件中的<mvc:annotation-driven  /> 2.添加如下配置 <bean class="org.springframework.web.ser ...

  3. C++11新特性——The C++ standard library, 2nd Edition 笔记(一)

    前言 这是我阅读<The C++ standard library, 2nd Edition>所做读书笔记的第一篇.这个系列基本上会以一章一篇的节奏来写,少数以C++03为主的章节会和其它 ...

  4. OC调用Swift

    Step by step swift integration for Xcode Objc-based project: Create new *.swift file (in Xcode) or a ...

  5. [转]Go与C语言的互操作

    Go有强烈的C背景,除了语法具有继承性外,其设计者以及其设计目标都与C语言有着千丝万缕的联系.在Go与C语言互操作(Interoperability)方面,Go更是提供了强大的支持.尤其是在Go中使用 ...

  6. python3.4用循环往mysql5.7中写数据并输出

    #!/usr/bin/env python # -*- coding:utf-8 -*- # __author__ = "blzhu" """ pyt ...

  7. Java源码更改的方式

    1.找到要改的类所在包名地址. 比如标签名的更改: <s:debug></s:debug> (1)ctril+鼠标左键========双击标签,就会弹出标签所在的类的文本 (2 ...

  8. BeautifulSoup基本步骤

    http://blog.csdn.net/kikaylee/article/details/56841789 ’BeautifulSoup是Python的一个库,最主要的功能就是从网页爬取我们需要的数 ...

  9. python编码(四)

    一.预备知识 字符集 1, 常用字符集分类 ASCII及其扩展字符集作用:表语英语及西欧语言.位数:ASCII是用7位表示的,能表示128个字符:其扩展使用8位表示,表示256个字符.范围:ASCII ...

  10. RepositionBars的用法和参数的意义(引用别人的)

    MFC窗口位置管理详细分析及实例 在一般用MFC编写的程序的窗口客户区中,可能有好几个子窗口(具有WM_CHILD风格的窗口).上边是工具栏,中间是视图窗口,下边是状态栏.三个窗 口在框架的客户区里和 ...