Add an UseRouter that takes Action<IRouteBuilder>
- Added an overload of UseRouter that takes Action<IRouteBuilder>, to make configuring standalone routing much less verbose. Addresses #332
This commit is contained in:
parent
322e1f5d9c
commit
4adc693cb5
|
|
@ -41,5 +41,30 @@ namespace Microsoft.AspNetCore.Builder
|
|||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue