Created
August 12, 2015 05:03
-
-
Save davidfowl/749b73d134f12d624fc9 to your computer and use it in GitHub Desktop.
Middleware that rejoins the parent pipeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
configuration(branchBuilder); | |
return builder.UseMiddleware<MapUseMiddleware>(branchBuilder); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment