Пример #1
0
        public static async Task main()
        {
            Context c = new Context();

            c.SetRequest("来自cx的请求");
            ApplicationCore application = new ApplicationCore();

            //第一个中间件
            application.Use(next => async context =>
            {
                await context.ResponseAsync("来自第1个中间件Start");
                await next(context);
                await context.ResponseAsync("来自第1个中间件End");
            })
            .Use(next => async context =>
            {
                await context.ResponseAsync("来自第2个中间件Start");
                await next(context);
                await context.ResponseAsync("来自第2个中间件End");
            })
            .Use(next => async context =>
            {
                await context.ResponseAsync("来自第3个中间件Start");
                await next(context);
                await context.ResponseAsync("来自第3个中间件End");
            })
            .Use(async(context, next) =>
            {
                await context.ResponseAsync("来自第4个中间件Start");
                await next();
                await context.ResponseAsync("来自第4个中间件End");
            })
            .Use(async(context, next) =>
            {
                await context.ResponseAsync("来自第5个中间件Start");
                //await next();
                await context.ResponseAsync("来自第5个中间件End");
            });

            RequestDelegate rd = application.Build();

            await rd(c);
        }