Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
Add an UseRouter that takes Action<IRouteBuilder>
Browse files Browse the repository at this point in the history
- Added an overload of UseRouter that takes Action<IRouteBuilder>, to
make configuring standalone routing much less verbose.

Addresses #332
  • Loading branch information
Muchiachio authored and rynowak committed Jul 1, 2016
1 parent 322e1f5 commit 4adc693
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Microsoft.AspNetCore.Routing/BuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,30 @@ public static IApplicationBuilder UseRouter(this IApplicationBuilder builder, IR

return builder.UseMiddleware<RouterMiddleware>(router);
}

/// <summary>
/// Adds a <see cref="RouterMiddleware"/> middleware to the specified <see cref="IApplicationBuilder"/>
/// with the <see cref="IRouter"/> built from configured <see cref="IRouteBuilder"/>.
/// </summary>
/// <param name="builder">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
/// <param name="action">An <see cref="Action{IRouteBuilder}"/> to configure the provided <see cref="IRouteBuilder"/>.</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IApplicationBuilder UseRouter(this IApplicationBuilder builder, Action<IRouteBuilder> 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());
}
}
}

0 comments on commit 4adc693

Please sign in to comment.