diff options
Diffstat (limited to 'src/Http/Routing/test/testassets/RoutingSandbox/UseRouterStartup.cs')
-rw-r--r-- | src/Http/Routing/test/testassets/RoutingSandbox/UseRouterStartup.cs | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/src/Http/Routing/test/testassets/RoutingSandbox/UseRouterStartup.cs b/src/Http/Routing/test/testassets/RoutingSandbox/UseRouterStartup.cs index a74b7f493e..59d3a577c5 100644 --- a/src/Http/Routing/test/testassets/RoutingSandbox/UseRouterStartup.cs +++ b/src/Http/Routing/test/testassets/RoutingSandbox/UseRouterStartup.cs @@ -9,35 +9,34 @@ using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing.Constraints; using Microsoft.Extensions.DependencyInjection; -namespace RoutingSandbox +namespace RoutingSandbox; + +public class UseRouterStartup { - public class UseRouterStartup - { - private static readonly TimeSpan RegexMatchTimeout = TimeSpan.FromSeconds(10); + private static readonly TimeSpan RegexMatchTimeout = TimeSpan.FromSeconds(10); - public void ConfigureServices(IServiceCollection services) - { - services.AddRouting(); - } + public void ConfigureServices(IServiceCollection services) + { + services.AddRouting(); + } - public void Configure(IApplicationBuilder app) + public void Configure(IApplicationBuilder app) + { + app.UseRouter(routes => { - app.UseRouter(routes => + routes.DefaultHandler = new RouteHandler((httpContext) => { - routes.DefaultHandler = new RouteHandler((httpContext) => - { - var request = httpContext.Request; - return httpContext.Response.WriteAsync($"Verb = {request.Method.ToUpperInvariant()} - Path = {request.Path} - Route values - {string.Join(", ", httpContext.GetRouteData().Values)}"); - }); - - routes.MapGet("api/get/{id}", (request, response, routeData) => response.WriteAsync($"API Get {routeData.Values["id"]}")) - .MapMiddlewareRoute("api/middleware", (appBuilder) => appBuilder.Run(httpContext => httpContext.Response.WriteAsync("Middleware!"))) - .MapRoute( - name: "AllVerbs", - template: "api/all/{name}/{lastName?}", - defaults: new { lastName = "Doe" }, - constraints: new { lastName = new RegexRouteConstraint(new Regex("[a-zA-Z]{3}", RegexOptions.CultureInvariant, RegexMatchTimeout)) }); + var request = httpContext.Request; + return httpContext.Response.WriteAsync($"Verb = {request.Method.ToUpperInvariant()} - Path = {request.Path} - Route values - {string.Join(", ", httpContext.GetRouteData().Values)}"); }); - } + + routes.MapGet("api/get/{id}", (request, response, routeData) => response.WriteAsync($"API Get {routeData.Values["id"]}")) + .MapMiddlewareRoute("api/middleware", (appBuilder) => appBuilder.Run(httpContext => httpContext.Response.WriteAsync("Middleware!"))) + .MapRoute( + name: "AllVerbs", + template: "api/all/{name}/{lastName?}", + defaults: new { lastName = "Doe" }, + constraints: new { lastName = new RegexRouteConstraint(new Regex("[a-zA-Z]{3}", RegexOptions.CultureInvariant, RegexMatchTimeout)) }); + }); } } |