Rename a bunch of old stuff

This commit is contained in:
Ryan Nowak 2017-10-25 23:55:24 -07:00
parent 81ddda7b96
commit bb413c6ac3
13 changed files with 88 additions and 90 deletions

View File

@ -35,20 +35,20 @@ namespace DispatcherSample
{
Addresses =
{
new TemplateAddress("{id?}", new { controller = "Home", action = "Index", }, "Home:Index()"),
new TemplateAddress("Home/About/{id?}", new { controller = "Home", action = "About", }, "Home:About()"),
new TemplateAddress("Admin/Index/{id?}", new { controller = "Admin", action = "Index", }, "Admin:Index()"),
new TemplateAddress("Admin/Users/{id?}", new { controller = "Admin", action = "Users", }, "Admin:GetUsers()/Admin:EditUsers()"),
new RoutePatternAddress("{id?}", new { controller = "Home", action = "Index", }, "Home:Index()"),
new RoutePatternAddress("Home/About/{id?}", new { controller = "Home", action = "About", }, "Home:About()"),
new RoutePatternAddress("Admin/Index/{id?}", new { controller = "Admin", action = "Index", }, "Admin:Index()"),
new RoutePatternAddress("Admin/Users/{id?}", new { controller = "Admin", action = "Users", }, "Admin:GetUsers()/Admin:EditUsers()"),
},
Endpoints =
{
new TemplateEndpoint("{id?}", new { controller = "Home", action = "Index", }, Home_Index, "Home:Index()"),
new TemplateEndpoint("Home/{id?}", new { controller = "Home", action = "Index", }, Home_Index, "Home:Index()"),
new TemplateEndpoint("Home/Index/{id?}", new { controller = "Home", action = "Index", }, Home_Index, "Home:Index()"),
new TemplateEndpoint("Home/About/{id?}", new { controller = "Home", action = "About", }, Home_About, "Home:About()"),
new TemplateEndpoint("Admin/Index/{id?}", new { controller = "Admin", action = "Index", }, Admin_Index, "Admin:Index()"),
new TemplateEndpoint("Admin/Users/{id?}", new { controller = "Admin", action = "Users", }, "GET", Admin_GetUsers, "Admin:GetUsers()", new AuthorizationPolicyMetadata("Admin")),
new TemplateEndpoint("Admin/Users/{id?}", new { controller = "Admin", action = "Users", }, "POST", Admin_EditUsers, "Admin:EditUsers()", new AuthorizationPolicyMetadata("Admin")),
new RoutePatternEndpoint("{id?}", new { controller = "Home", action = "Index", }, Home_Index, "Home:Index()"),
new RoutePatternEndpoint("Home/{id?}", new { controller = "Home", action = "Index", }, Home_Index, "Home:Index()"),
new RoutePatternEndpoint("Home/Index/{id?}", new { controller = "Home", action = "Index", }, Home_Index, "Home:Index()"),
new RoutePatternEndpoint("Home/About/{id?}", new { controller = "Home", action = "About", }, Home_About, "Home:About()"),
new RoutePatternEndpoint("Admin/Index/{id?}", new { controller = "Admin", action = "Index", }, Admin_Index, "Admin:Index()"),
new RoutePatternEndpoint("Admin/Users/{id?}", new { controller = "Admin", action = "Users", }, "GET", Admin_GetUsers, "Admin:GetUsers()", new AuthorizationPolicyMetadata("Admin")),
new RoutePatternEndpoint("Admin/Users/{id?}", new { controller = "Admin", action = "Users", }, "POST", Admin_EditUsers, "Admin:EditUsers()", new AuthorizationPolicyMetadata("Admin")),
},
};
}
@ -62,7 +62,7 @@ namespace DispatcherSample
logger.LogInformation("Executing fake CORS middleware");
var feature = context.Features.Get<IDispatcherFeature>();
var policy = feature.Endpoint?.Metadata.OfType<ICorsPolicyMetadata>().LastOrDefault();
var policy = feature.Endpoint?.Metadata.GetMetadata<ICorsPolicyMetadata>();
logger.LogInformation("using CORS policy {PolicyName}", policy?.Name ?? "default");
await next.Invoke();
@ -73,7 +73,7 @@ namespace DispatcherSample
logger.LogInformation("Executing fake AuthZ middleware");
var feature = context.Features.Get<IDispatcherFeature>();
var policy = feature.Endpoint?.Metadata.OfType<IAuthorizationPolicyMetadata>().LastOrDefault();
var policy = feature.Endpoint?.Metadata.GetMetadata<IAuthorizationPolicyMetadata>();
if (policy != null)
{
logger.LogInformation("using Auth policy {PolicyName}", policy.Name);

View File

@ -30,14 +30,14 @@ namespace Microsoft.Extensions.DependencyInjection
services.TryAddSingleton<AddressTable, DefaultAddressTable>();
services.TryAddSingleton<TemplateFactory, DefaultTemplateFactory>();
services.TryAddSingleton<ITemplateFactoryComponent, RoutePatternTemplateFactory>();
services.TryAddSingleton<TemplateAddressSelector>();
services.TryAddSingleton<RoutePatternAddressSelector>();
//
// Misc Infrastructure
//
services.TryAddSingleton<RoutePatternBinderFactory>();
services.TryAddEnumerable(ServiceDescriptor.Singleton<IHandlerFactory, TemplateEndpointHandlerFactory>());
services.TryAddEnumerable(ServiceDescriptor.Singleton<IHandlerFactory, RoutePatternEndpointHandlerFactory>());
return services;
}

View File

@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Dispatcher
var fallbackEndpoints = new List<Endpoint>();
for (var i = context.Endpoints.Count - 1; i >= 0; i--)
{
var endpoint = context.Endpoints[i] as ITemplateEndpoint;
var endpoint = context.Endpoints[i] as IRoutePatternEndpoint;
if (endpoint == null || endpoint.HttpMethod == null)
{
// No metadata.

View File

@ -3,9 +3,9 @@
namespace Microsoft.AspNetCore.Dispatcher
{
public interface ITemplateAddress
public interface IRoutePatternAddress
{
string Template { get; }
string Pattern { get; }
DispatcherValueCollection Defaults { get; }
}

View File

@ -3,11 +3,11 @@
namespace Microsoft.AspNetCore.Dispatcher
{
public interface ITemplateEndpoint
public interface IRoutePatternEndpoint
{
string HttpMethod { get; }
string Template { get; }
string Pattern { get; }
DispatcherValueCollection Values { get; }
}

View File

@ -2,23 +2,21 @@
// 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 System.Linq;
namespace Microsoft.AspNetCore.Dispatcher
{
public class TemplateAddress : Address, ITemplateAddress
public class RoutePatternAddress : Address, IRoutePatternAddress
{
public TemplateAddress(string template, object values, params object[] metadata)
: this(template, values, null, metadata)
public RoutePatternAddress(string pattern, object values, params object[] metadata)
: this(pattern, values, null, metadata)
{
}
public TemplateAddress(string template, object values, string displayName, params object[] metadata)
public RoutePatternAddress(string pattern, object values, string displayName, params object[] metadata)
{
if (template == null)
if (pattern == null)
{
throw new ArgumentNullException(nameof(template));
throw new ArgumentNullException(nameof(pattern));
}
if (metadata == null)
@ -26,7 +24,7 @@ namespace Microsoft.AspNetCore.Dispatcher
throw new ArgumentNullException(nameof(metadata));
}
Template = template;
Pattern = pattern;
Defaults = new DispatcherValueCollection(values);
DisplayName = displayName;
Metadata = new MetadataCollection(metadata);
@ -36,7 +34,7 @@ namespace Microsoft.AspNetCore.Dispatcher
public override MetadataCollection Metadata { get; }
public string Template { get; }
public string Pattern { get; }
public DispatcherValueCollection Defaults { get; }
}

View File

@ -7,11 +7,11 @@ using System.Collections.Generic;
namespace Microsoft.AspNetCore.Dispatcher
{
// This isn't a proposed design, just a placeholder to demonstrate that things are wired up correctly.
public class TemplateAddressSelector
public class RoutePatternAddressSelector
{
private readonly AddressTable _addressTable;
public TemplateAddressSelector(AddressTable addressTable)
public RoutePatternAddressSelector(AddressTable addressTable)
{
if (addressTable == null)
{
@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Dispatcher
for (var j = 0; j < group.Count; j++)
{
var address = group[j] as ITemplateAddress;
var address = group[j] as IRoutePatternAddress;
if (address == null)
{
continue;
@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Dispatcher
return null;
}
private bool IsMatch(ITemplateAddress address, DispatcherValueCollection values)
private bool IsMatch(IRoutePatternAddress address, DispatcherValueCollection values)
{
foreach (var kvp in address.Defaults)
{

View File

@ -8,59 +8,59 @@ using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Dispatcher
{
public class TemplateEndpoint : Endpoint, ITemplateEndpoint
public class RoutePatternEndpoint : Endpoint, IRoutePatternEndpoint
{
public TemplateEndpoint(string template, RequestDelegate requestDelegate, params object[] metadata)
: this(template, (object)null, (string)null, requestDelegate, null, metadata)
public RoutePatternEndpoint(string pattern, RequestDelegate requestDelegate, params object[] metadata)
: this(pattern, (object)null, (string)null, requestDelegate, null, metadata)
{
}
public TemplateEndpoint(string template, Func<RequestDelegate, RequestDelegate> delegateFactory, params object[] metadata)
: this(template, (object)null, (string)null, delegateFactory, null, metadata)
public RoutePatternEndpoint(string pattern, Func<RequestDelegate, RequestDelegate> delegateFactory, params object[] metadata)
: this(pattern, (object)null, (string)null, delegateFactory, null, metadata)
{
}
public TemplateEndpoint(string template, object values, RequestDelegate requestDelegate, params object[] metadata)
: this(template, values, null, requestDelegate, null, metadata)
public RoutePatternEndpoint(string pattern, object values, RequestDelegate requestDelegate, params object[] metadata)
: this(pattern, values, null, requestDelegate, null, metadata)
{
}
public TemplateEndpoint(string template, object values, Func<RequestDelegate, RequestDelegate> delegateFactory, params object[] metadata)
: this(template, values, null, delegateFactory, null, metadata)
public RoutePatternEndpoint(string pattern, object values, Func<RequestDelegate, RequestDelegate> delegateFactory, params object[] metadata)
: this(pattern, values, null, delegateFactory, null, metadata)
{
}
public TemplateEndpoint(string template, object values, RequestDelegate requestDelegate, string displayName, params object[] metadata)
: this(template, values, null, requestDelegate, displayName, metadata)
public RoutePatternEndpoint(string pattern, object values, RequestDelegate requestDelegate, string displayName, params object[] metadata)
: this(pattern, values, null, requestDelegate, displayName, metadata)
{
}
public TemplateEndpoint(string template, object values, Func<RequestDelegate, RequestDelegate> delegateFactory, string displayName, params object[] metadata)
: this(template, values, null, delegateFactory, displayName, metadata)
public RoutePatternEndpoint(string pattern, object values, Func<RequestDelegate, RequestDelegate> delegateFactory, string displayName, params object[] metadata)
: this(pattern, values, null, delegateFactory, displayName, metadata)
{
}
public TemplateEndpoint(string template, object values, string httpMethod, RequestDelegate requestDelegate, params object[] metadata)
: this(template, values, httpMethod, requestDelegate, null, metadata)
public RoutePatternEndpoint(string pattern, object values, string httpMethod, RequestDelegate requestDelegate, params object[] metadata)
: this(pattern, values, httpMethod, requestDelegate, null, metadata)
{
}
public TemplateEndpoint(string template, object values, string httpMethod, Func<RequestDelegate, RequestDelegate> delegateFactory, params object[] metadata)
: this(template, values, httpMethod, delegateFactory, null, metadata)
public RoutePatternEndpoint(string pattern, object values, string httpMethod, Func<RequestDelegate, RequestDelegate> delegateFactory, params object[] metadata)
: this(pattern, values, httpMethod, delegateFactory, null, metadata)
{
}
public TemplateEndpoint(
string template,
public RoutePatternEndpoint(
string pattern,
object values,
string httpMethod,
RequestDelegate requestDelegate,
string displayName,
params object[] metadata)
{
if (template == null)
if (pattern == null)
{
throw new ArgumentNullException(nameof(template));
throw new ArgumentNullException(nameof(pattern));
}
if (requestDelegate == null)
@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Dispatcher
throw new ArgumentNullException(nameof(metadata));
}
Template = template;
Pattern = pattern;
Values = new DispatcherValueCollection(values);
HttpMethod = httpMethod;
HandlerFactory = (next) => requestDelegate;
@ -81,17 +81,17 @@ namespace Microsoft.AspNetCore.Dispatcher
Metadata = new MetadataCollection(metadata);
}
public TemplateEndpoint(
string template,
public RoutePatternEndpoint(
string pattern,
object values,
string httpMethod,
Func<RequestDelegate, RequestDelegate> delegateFactory,
string displayName,
params object[] metadata)
{
if (template == null)
if (pattern == null)
{
throw new ArgumentNullException(nameof(template));
throw new ArgumentNullException(nameof(pattern));
}
if (delegateFactory == null)
@ -104,7 +104,7 @@ namespace Microsoft.AspNetCore.Dispatcher
throw new ArgumentNullException(nameof(metadata));
}
Template = template;
Pattern = pattern;
Values = new DispatcherValueCollection(values);
HttpMethod = httpMethod;
HandlerFactory = delegateFactory;
@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.Dispatcher
public Func<RequestDelegate, RequestDelegate> HandlerFactory { get; }
public string Template { get; }
public string Pattern { get; }
public DispatcherValueCollection Values { get; }
}

View File

@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Dispatcher
{
public sealed class TemplateEndpointHandlerFactory : IHandlerFactory
public sealed class RoutePatternEndpointHandlerFactory : IHandlerFactory
{
public Func<RequestDelegate, RequestDelegate> CreateHandler(Endpoint endpoint)
{
@ -15,9 +15,9 @@ namespace Microsoft.AspNetCore.Dispatcher
throw new ArgumentNullException(nameof(endpoint));
}
if (endpoint is TemplateEndpoint templateEndpoint)
if (endpoint is RoutePatternEndpoint routePatternEndpoint)
{
return templateEndpoint.HandlerFactory;
return routePatternEndpoint.HandlerFactory;
}
return null;

View File

@ -7,10 +7,10 @@ namespace Microsoft.AspNetCore.Dispatcher
{
internal class RoutePatternTemplateFactory : TemplateFactory<DispatcherValueCollection>
{
private readonly TemplateAddressSelector _selector;
private readonly RoutePatternAddressSelector _selector;
private readonly RoutePatternBinderFactory _binderFactory;
public RoutePatternTemplateFactory(TemplateAddressSelector selector, RoutePatternBinderFactory binderFactory)
public RoutePatternTemplateFactory(RoutePatternAddressSelector selector, RoutePatternBinderFactory binderFactory)
{
if (selector == null)
{
@ -39,9 +39,9 @@ namespace Microsoft.AspNetCore.Dispatcher
return null;
}
if (address is ITemplateAddress templateAddress)
if (address is IRoutePatternAddress templateAddress)
{
var binder = _binderFactory.Create(templateAddress.Template, templateAddress.Defaults);
var binder = _binderFactory.Create(templateAddress.Pattern, templateAddress.Defaults);
return new RoutePatternTemplate(binder);
}

View File

@ -82,7 +82,7 @@ namespace Microsoft.AspNetCore.Routing.Dispatcher
if (context.Endpoint != null)
{
if (context.Endpoint is ITemplateEndpoint templateEndpoint)
if (context.Endpoint is IRoutePatternEndpoint templateEndpoint)
{
foreach (var kvp in templateEndpoint.Values)
{
@ -128,16 +128,16 @@ namespace Microsoft.AspNetCore.Routing.Dispatcher
{
var endpoint = endpoints[i];
var templateEndpoint = endpoint as ITemplateEndpoint;
var templateEndpoint = endpoint as IRoutePatternEndpoint;
if (templateEndpoint == null)
{
continue;
}
if (!groups.TryGetValue(new Key(0, templateEndpoint.Template), out var group))
if (!groups.TryGetValue(new Key(0, templateEndpoint.Pattern), out var group))
{
group = new List<Endpoint>();
groups.Add(new Key(0, templateEndpoint.Template), group);
groups.Add(new Key(0, templateEndpoint.Pattern), group);
}
group.Add(endpoint);

View File

@ -34,7 +34,7 @@ namespace Microsoft.AspNetCore.Dispatcher.FunctionalTest
logger.LogInformation("Executing fake CORS middleware");
var feature = context.Features.Get<IDispatcherFeature>();
var policy = feature.Endpoint?.Metadata.OfType<CorsPolicyMetadata>().LastOrDefault();
var policy = feature.Endpoint?.Metadata.GetMetadata<CorsPolicyMetadata>();
logger.LogInformation("using CORS policy {PolicyName}", policy?.Name ?? "default");
await next(context);
@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Dispatcher.FunctionalTest
logger.LogInformation("Executing fake AuthZ middleware");
var feature = context.Features.Get<IDispatcherFeature>();
var policy = feature.Endpoint?.Metadata.OfType<AuthorizationPolicyMetadata>().LastOrDefault();
var policy = feature.Endpoint?.Metadata.GetMetadata<AuthorizationPolicyMetadata>();
if (policy != null)
{
logger.LogInformation("using Auth policy {PolicyName}", policy.Name);
@ -61,18 +61,18 @@ namespace Microsoft.AspNetCore.Dispatcher.FunctionalTest
{
Endpoints =
{
new TemplateEndpoint("api/products", Products_Fallback),
new TemplateEndpoint("api/products", new { controller = "Products", action = "Get", }, "GET", Products_Get),
new TemplateEndpoint("api/products/{id}", new { controller = "Products", action = "Get", }, "GET", Products_GetWithId),
new TemplateEndpoint("api/products", new { controller = "Products", action = "Post", }, "POST", Products_Post),
new TemplateEndpoint("api/products/{id}", new { controller = "Products", action = "Put", }, "PUT", Products_Put),
new RoutePatternEndpoint("api/products", Products_Fallback),
new RoutePatternEndpoint("api/products", new { controller = "Products", action = "Get", }, "GET", Products_Get),
new RoutePatternEndpoint("api/products/{id}", new { controller = "Products", action = "Get", }, "GET", Products_GetWithId),
new RoutePatternEndpoint("api/products", new { controller = "Products", action = "Post", }, "POST", Products_Post),
new RoutePatternEndpoint("api/products/{id}", new { controller = "Products", action = "Put", }, "PUT", Products_Put),
},
Selectors =
{
new HttpMethodEndpointSelector(),
},
}, new TemplateEndpointHandlerFactory());
}, new RoutePatternEndpointHandlerFactory());
}
private Task Products_Fallback(HttpContext httpContext) => httpContext.Response.WriteAsync("Hello, Products_Fallback");

View File

@ -21,15 +21,15 @@ namespace Microsoft.AspNetCore.Dispatcher
// Arrange
var endpoints = new List<Endpoint>()
{
new TemplateEndpoint("{controller=Home}/{action=Index}/{id?}", new { controller = "Products", action = "Get", }, "GET", Products_Get, "Products:Get()"),
new TemplateEndpoint("{controller=Home}/{action=Index}/{id?}", new { controller = "Products", action = "Create", }, "POST", Products_Post, "Products:Post()"),
new RoutePatternEndpoint("{controller=Home}/{action=Index}/{id?}", new { controller = "Products", action = "Get", }, "GET", Products_Get, "Products:Get()"),
new RoutePatternEndpoint("{controller=Home}/{action=Index}/{id?}", new { controller = "Products", action = "Create", }, "POST", Products_Post, "Products:Post()"),
};
var (context, selector) = CreateContextAndSelector(httpMethod, endpoints);
// Act
await selector.SelectAsync(context);
var templateEndpoints = context.Endpoints.Cast<TemplateEndpoint>();
var templateEndpoints = context.Endpoints.Cast<RoutePatternEndpoint>();
// Assert
Assert.Collection(
@ -43,8 +43,8 @@ namespace Microsoft.AspNetCore.Dispatcher
// Arrange
var endpoints = new List<Endpoint>()
{
new TemplateEndpoint("{controller=Home}/{action=Index}/{id?}", new { controller = "Products", action = "Get", }, "GET", Products_Get, "Products:Get()"),
new TemplateEndpoint("{controller=Home}/{action=Index}/{id?}", new { controller = "Products", action = "Create", }, "POST", Products_Post, "Products:Post()"),
new RoutePatternEndpoint("{controller=Home}/{action=Index}/{id?}", new { controller = "Products", action = "Get", }, "GET", Products_Get, "Products:Get()"),
new RoutePatternEndpoint("{controller=Home}/{action=Index}/{id?}", new { controller = "Products", action = "Create", }, "POST", Products_Post, "Products:Post()"),
};
var (context, selector) = CreateContextAndSelector("PUT", endpoints);
@ -64,16 +64,16 @@ namespace Microsoft.AspNetCore.Dispatcher
// Arrange
var endpoints = new List<Endpoint>()
{
new TemplateEndpoint("{controller=Home}/{action=Index}/{id?}", new { controller = "Products", action = "Get", }, "GET", Products_Get, "Products:Get()"),
new TemplateEndpoint("{controller=Home}/{action=Index}/{id?}", new { controller = "Products", action = "Create", }, "POST", Products_Post, "Products:Post()"),
new TemplateEndpoint("{controller=Home}/{action=Index}/{id?}", new { controller = "Products", action = "Get", }, Products_Get),
new RoutePatternEndpoint("{controller=Home}/{action=Index}/{id?}", new { controller = "Products", action = "Get", }, "GET", Products_Get, "Products:Get()"),
new RoutePatternEndpoint("{controller=Home}/{action=Index}/{id?}", new { controller = "Products", action = "Create", }, "POST", Products_Post, "Products:Post()"),
new RoutePatternEndpoint("{controller=Home}/{action=Index}/{id?}", new { controller = "Products", action = "Get", }, Products_Get),
};
var (context, selector) = CreateContextAndSelector(httpMethod, endpoints);
// Act
await selector.SelectAsync(context);
var templateEndpoints = context.Endpoints.Cast<TemplateEndpoint>();
var templateEndpoints = context.Endpoints.Cast<RoutePatternEndpoint>();
// Assert
Assert.Collection(