Adding routebuilder
This commit is contained in:
parent
5ee991cf61
commit
42ce8c6594
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Routing;
|
||||
|
||||
namespace RoutingSample
|
||||
{
|
||||
public static class RouteBuilderExtensions
|
||||
{
|
||||
public static void AddPrefixRoute(this IRouteBuilder builder, string prefix)
|
||||
{
|
||||
builder.Routes.Add(new PrefixRoute(builder.Endpoint, prefix));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
#if NET45
|
||||
|
||||
using Microsoft.AspNet.Abstractions;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using Microsoft.AspNet.Routing.Owin;
|
||||
using Microsoft.AspNet.Routing.Template;
|
||||
using Owin;
|
||||
|
|
@ -25,10 +26,13 @@ namespace RoutingSample
|
|||
var endpoint1 = new HttpContextRouteEndpoint(async (context) => await context.Response.WriteAsync("match1"));
|
||||
var endpoint2 = new HttpContextRouteEndpoint(async (context) => await context.Response.WriteAsync("Hello, World!"));
|
||||
|
||||
routes.Add(new PrefixRoute(endpoint1, "api/store"));
|
||||
routes.Add(new TemplateRoute(endpoint1, "api/checkout/{*extra}"));
|
||||
routes.Add(new PrefixRoute(endpoint2, "hello/world"));
|
||||
routes.Add(new PrefixRoute(endpoint1, ""));
|
||||
var rb1 = new RouteBuilder(endpoint1, routes);
|
||||
rb1.AddPrefixRoute("api/store");
|
||||
rb1.AddTemplateRoute("api/checkout/{*extra}");
|
||||
|
||||
var rb2 = new RouteBuilder(endpoint2, routes);
|
||||
rb2.AddPrefixRoute("hello/world");
|
||||
rb2.AddPrefixRoute("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Routing
|
||||
{
|
||||
public interface IRouteBuilder
|
||||
{
|
||||
IRouteEndpoint Endpoint
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
IRouteCollection Routes
|
||||
{
|
||||
get;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Routing
|
||||
{
|
||||
public class RouteBuilder : IRouteBuilder
|
||||
{
|
||||
public RouteBuilder(IRouteEndpoint endpoint, IRouteCollection routes)
|
||||
{
|
||||
Endpoint = endpoint;
|
||||
Routes = routes;
|
||||
}
|
||||
public IRouteEndpoint Endpoint
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public IRouteCollection Routes
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.AspNet.Routing.Template
|
||||
{
|
||||
public static class RouteBuilderExtensions
|
||||
{
|
||||
public static void AddTemplateRoute(this IRouteBuilder builder, string template)
|
||||
{
|
||||
AddTemplateRoute(builder, template, null);
|
||||
}
|
||||
|
||||
public static void AddTemplateRoute(this IRouteBuilder builder, string template, IDictionary<string, object> defaults)
|
||||
{
|
||||
builder.Routes.Add(new TemplateRoute(builder.Endpoint, template, defaults));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue