Skip to content

Instantly share code, notes, and snippets.

Created August 12, 2015 05:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save davidfowl/749b73d134f12d624fc9 to your computer and use it in GitHub Desktop.
Middleware that rejoins the parent pipeline
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
namespace WebApplication58
public class MapUseMiddleware
private readonly RequestDelegate _childPipeline;
public MapUseMiddleware(RequestDelegate next, IApplicationBuilder subBuilder)
subBuilder.Use(subNext =>
return ctx => next(ctx);
_childPipeline = subBuilder.Build();
public Task Invoke(HttpContext httpContext)
return _childPipeline(httpContext);
// Extension method used to add the middleware to the HTTP request pipeline.
public static class MapUseMiddlewareExtensions
public static IApplicationBuilder UseMapMiddleware(this IApplicationBuilder builder, Action<IApplicationBuilder> configuration)
var branchBuilder = builder.New();
return builder.UseMiddleware<MapUseMiddleware>(branchBuilder);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment