diff --git a/src/Microsoft.AspNetCore.Routing/BuilderExtensions.cs b/src/Microsoft.AspNetCore.Routing/BuilderExtensions.cs index 0963019f2d..2ec4318737 100644 --- a/src/Microsoft.AspNetCore.Routing/BuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Routing/BuilderExtensions.cs @@ -41,5 +41,30 @@ namespace Microsoft.AspNetCore.Builder return builder.UseMiddleware(router); } + + /// + /// Adds a middleware to the specified + /// with the built from configured . + /// + /// The to add the middleware to. + /// An to configure the provided . + /// A reference to this instance after the operation has completed. + public static IApplicationBuilder UseRouter(this IApplicationBuilder builder, Action action) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (action == null) + { + throw new ArgumentNullException(nameof(action)); + } + + var routeBuilder = new RouteBuilder(builder); + action(routeBuilder); + + return builder.UseRouter(routeBuilder.Build()); + } } } \ No newline at end of file