Clean up endpoint builder (#791)

This commit is contained in:
James Newton-King 2018-09-13 10:27:01 +12:00 committed by GitHub
parent cf484a49d0
commit 9df5918239
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 24 deletions

View File

@ -93,7 +93,7 @@ namespace RoutingSample.Web
},
"/graph",
"DFA Graph",
new object[] { new HttpMethodMetadata(new[] { "GET", }) });
new HttpMethodMetadata(new[] { "GET", }));
builder.MapEndpoint(
(httpContext) =>
{
@ -107,10 +107,7 @@ namespace RoutingSample.Web
},
"/WithSingleAsteriskCatchAll/{*path}",
"WithSingleAsteriskCatchAll",
new object[]
{
new RouteValuesAddressMetadata(routeName: "WithSingleAsteriskCatchAll", requiredValues: new RouteValueDictionary()),
});
new RouteValuesAddressMetadata(routeName: "WithSingleAsteriskCatchAll", requiredValues: new RouteValueDictionary()));
builder.MapEndpoint(
(httpContext) =>
{
@ -124,10 +121,7 @@ namespace RoutingSample.Web
},
"/WithDoubleAsteriskCatchAll/{**path}",
"WithDoubleAsteriskCatchAll",
new object[]
{
new RouteValuesAddressMetadata(routeName: "WithDoubleAsteriskCatchAll", requiredValues: new RouteValueDictionary())
});
new RouteValuesAddressMetadata(routeName: "WithDoubleAsteriskCatchAll", requiredValues: new RouteValueDictionary()));
});
// Imagine some more stuff here...

View File

@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Builder
{
public static class MapEndpointEndpointDataSourceBuilderExtensions
{
public static MatcherEndpointBuilder MapEndpoint(
public static RouteEndpointBuilder MapEndpoint(
this EndpointDataSourceBuilder builder,
RequestDelegate requestDelegate,
string pattern,
@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Builder
return MapEndpoint(builder, requestDelegate, pattern, displayName, metadata: null);
}
public static MatcherEndpointBuilder MapEndpoint(
public static RouteEndpointBuilder MapEndpoint(
this EndpointDataSourceBuilder builder,
RequestDelegate requestDelegate,
RoutePattern pattern,
@ -30,26 +30,26 @@ namespace Microsoft.AspNetCore.Builder
return MapEndpoint(builder, requestDelegate, pattern, displayName, metadata: null);
}
public static MatcherEndpointBuilder MapEndpoint(
public static RouteEndpointBuilder MapEndpoint(
this EndpointDataSourceBuilder builder,
RequestDelegate requestDelegate,
string pattern,
string displayName,
IList<object> metadata)
params object[] metadata)
{
return MapEndpoint(builder, requestDelegate, RoutePatternFactory.Parse(pattern), displayName, metadata);
}
public static MatcherEndpointBuilder MapEndpoint(
public static RouteEndpointBuilder MapEndpoint(
this EndpointDataSourceBuilder builder,
RequestDelegate requestDelegate,
RoutePattern pattern,
string displayName,
IList<object> metadata)
params object[] metadata)
{
const int defaultOrder = 0;
var endpointBuilder = new MatcherEndpointBuilder(
var endpointBuilder = new RouteEndpointBuilder(
requestDelegate,
pattern,
defaultOrder);

View File

@ -8,6 +8,8 @@ namespace Microsoft.AspNetCore.Routing
{
public abstract class EndpointBuilder
{
public RequestDelegate RequestDelegate { get; set; }
public string DisplayName { get; set; }
public IList<object> Metadata { get; } = new List<object>();

View File

@ -1,22 +1,18 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing.Patterns;
namespace Microsoft.AspNetCore.Routing.Matching
namespace Microsoft.AspNetCore.Routing
{
public sealed class MatcherEndpointBuilder : EndpointBuilder
public sealed class RouteEndpointBuilder : EndpointBuilder
{
public RequestDelegate RequestDelegate { get; set; }
public RoutePattern RoutePattern { get; set; }
public int Order { get; set; }
public MatcherEndpointBuilder(
public RouteEndpointBuilder(
RequestDelegate requestDelegate,
RoutePattern routePattern,
int order)

View File

@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Routing.Matching
object metadata = new object();
RequestDelegate requestDelegate = (d) => null;
var builder = new MatcherEndpointBuilder(requestDelegate, RoutePatternFactory.Parse("/"), defaultOrder)
var builder = new RouteEndpointBuilder(requestDelegate, RoutePatternFactory.Parse("/"), defaultOrder)
{
DisplayName = "Display name!",
Metadata = { metadata }