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. ldd "symbol lookup error"问题解决

    http://www.linuxquestions.org/questions/slackware-14/symbol-lookup-error-usr-lib-libgtk-x11-2-0-so-0 ...

  2. shiro 实现 用户 a 操作b 的权限 ,用户 b 能够及时获知。b不需要退出登陆 。 关闭鉴权缓存,或者不配置缓存

    <bean id="myRealm" class="com.diancai.util.MyRealm"> <property name=&qu ...

  3. 导出jar文件

    当我们编好一段代码时,就需要将其导出成应用程序,即jar文件(jar文件就是在Java运行环境下运行的应用程序).今天,巩固就教大家用eclipse导出jar文件. 第一步:找到eclipse,双击打 ...

  4. KBMMW 4.83.00 发布

    新版本又来了,端午节都不让大家过好:) 这次终于支持ios 64了,不用我再手工改了. Components4Developers is a company established in 1999 w ...

  5. 2018.07.23 hdu5828 Rikka with Sequence(线段树)

    传送门 这道题维护区间加,区间开根,区间求和. 线段树常规操作. 首先回忆两道简单得多的线段树. 第一个:区间覆盖,区间加,区间求和. 第二个:区间开根,区间求和. 这两个是名副其实的常规操作. 但这 ...

  6. csdn的一次回答问题

    #coding:utf8 import tushare as ts import pandas as pd import numpy as np import pymysql,datetime imp ...

  7. py-函数基础

    定义: 函数是指将一组语句的集合通过一个名字(函数名)封装起来,要想执行这个函数,只需调用其函数名即可 特性: 1.减少重复代码2.使程序变的可扩展3.使程序变得易维护 函数参数 形参变量 只有在被调 ...

  8. Fortran 语法之流程控制

    -----------------------

  9. 8) pom.xml

    http://maven.apache.org/ref/3.3.3/maven-model/maven.html 执行mvn命令的时候默认文件名pom.xml 也可以通过 -f 指定 比如 mvn - ...

  10. Android中Activity启动过程探究

    首先追溯到Activity的启动,随便启动一个自己写的demo项目,使用DDMS进行debug标记,然后在Debug中把主线程暂停,可以看到调用栈.如下图所示: 于是我们先看android.app.A ...