integrating abstractions with routing
This commit is contained in:
parent
c796188231
commit
0eb5ff0b87
|
|
@ -17,6 +17,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{95359B4B-4
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.Routing.Tests.net45", "test\Microsoft.AspNet.Routing.Tests\Microsoft.AspNet.Routing.Tests.net45.csproj", "{3775A966-0876-45C3-A67F-0E544BC48D55}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RoutingSample.k10", "samples\RoutingSample\RoutingSample.k10.csproj", "{1BB31C1A-C6F8-4C00-BD30-92EF775276BE}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
@ -39,6 +41,10 @@ Global
|
|||
{3775A966-0876-45C3-A67F-0E544BC48D55}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3775A966-0876-45C3-A67F-0E544BC48D55}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3775A966-0876-45C3-A67F-0E544BC48D55}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1BB31C1A-C6F8-4C00-BD30-92EF775276BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1BB31C1A-C6F8-4C00-BD30-92EF775276BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1BB31C1A-C6F8-4C00-BD30-92EF775276BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1BB31C1A-C6F8-4C00-BD30-92EF775276BE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
@ -47,6 +53,7 @@ Global
|
|||
{16537084-C16D-4885-B90F-18BAC218F85B} = {0E966C37-7334-4D96-AAF6-9F49FBD166E3}
|
||||
{1366B89C-F603-4088-B313-FA053C51BAC6} = {0E966C37-7334-4D96-AAF6-9F49FBD166E3}
|
||||
{121DC7B4-E29B-45E1-BF7E-314842F99A0D} = {C3ADD55B-B9C7-4061-8AD4-6A70D1AE3B2E}
|
||||
{1BB31C1A-C6F8-4C00-BD30-92EF775276BE} = {C3ADD55B-B9C7-4061-8AD4-6A70D1AE3B2E}
|
||||
{3775A966-0876-45C3-A67F-0E544BC48D55} = {95359B4B-4C85-4B44-A75B-0621905C4CF6}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Abstractions;
|
||||
using Microsoft.AspNet.Routing;
|
||||
|
||||
namespace RoutingSample
|
||||
{
|
||||
public class HttpContextRouteEndpoint : IRouteEndpoint
|
||||
{
|
||||
private readonly Func<HttpContext, Task> _appFunc;
|
||||
|
||||
public HttpContextRouteEndpoint(Func<HttpContext, Task> appFunc)
|
||||
{
|
||||
_appFunc = appFunc;
|
||||
}
|
||||
|
||||
public async Task<bool> Send(HttpContext context)
|
||||
{
|
||||
await _appFunc(context);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
#if NET45
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -18,10 +20,14 @@ namespace RoutingSample
|
|||
_appFunc = appFunc;
|
||||
}
|
||||
|
||||
public Task Invoke(HttpContext context)
|
||||
public async Task<bool> Send(HttpContext context)
|
||||
{
|
||||
var owinContext = context.GetFeature<ICanHasOwinEnvironment>().Environment;
|
||||
return _appFunc(owinContext);
|
||||
await _appFunc(owinContext);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
#if NET45
|
||||
using System;
|
||||
using Microsoft.Owin.Hosting;
|
||||
|
||||
|
|
@ -20,3 +21,4 @@ namespace RoutingSample
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
#if NET45
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Abstractions;
|
||||
using Microsoft.AspNet.Routing.Owin;
|
||||
using Owin;
|
||||
using Microsoft.AspNet.PipelineCore.Owin;
|
||||
|
|
@ -15,13 +18,19 @@ namespace RoutingSample
|
|||
{
|
||||
internal class Startup
|
||||
{
|
||||
public void Configuration(IAppBuilder appBuilder)
|
||||
public void Configuration(IAppBuilder builder)
|
||||
{
|
||||
var routes = appBuilder.UseRouter();
|
||||
|
||||
builder.UseErrorPage();
|
||||
|
||||
OwinRouteEndpoint endpoint1 = new OwinRouteEndpoint(async (context) => await WriteToBodyAsync(context, "match1"));
|
||||
OwinRouteEndpoint endpoint2 = new OwinRouteEndpoint(async (context) => await WriteToBodyAsync(context, "Hello, World!"));
|
||||
builder.UseBuilder(ConfigureRoutes);
|
||||
}
|
||||
|
||||
private void ConfigureRoutes(IBuilder builder)
|
||||
{
|
||||
var routes = builder.UseRouter();
|
||||
|
||||
var endpoint1 = new OwinRouteEndpoint(async (context) => await WriteToBodyAsync(context, "match1"));
|
||||
var endpoint2 = new HttpContextRouteEndpoint(async (context) => await context.Response.WriteAsync("Hello, World!"));
|
||||
|
||||
routes.Add(new PrefixRoute(endpoint1, "api/store"));
|
||||
routes.Add(new PrefixRoute(endpoint1, "api/checkout"));
|
||||
|
|
@ -38,3 +47,5 @@ namespace RoutingSample
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,9 +3,6 @@
|
|||
"dependencies": {
|
||||
"Microsoft.AspNet.Abstractions" : "0.1-alpha-*",
|
||||
"Microsoft.AspNet.AppBuilderSupport": "0.1-alpha-*",
|
||||
"Microsoft.AspNet.FeatureModel": "0.1-alpha-*",
|
||||
"Microsoft.AspNet.HttpFeature": "0.1-alpha-*",
|
||||
"Microsoft.AspNet.PipelineCore": "0.1-alpha-*",
|
||||
"Microsoft.AspNet.Routing" : ""
|
||||
},
|
||||
"configurations": {
|
||||
|
|
@ -13,9 +10,11 @@
|
|||
"dependencies": {
|
||||
"Owin": "1.0",
|
||||
"Microsoft.Owin" : "2.1.0",
|
||||
"Microsoft.Owin.Diagnostics" : "2.1.0",
|
||||
"Microsoft.Owin.Host.HttpListener" : "2.1.0",
|
||||
"Microsoft.Owin.Hosting" : "2.1.0"
|
||||
}
|
||||
}
|
||||
},
|
||||
"k10": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,11 @@ namespace Microsoft.AspNet.Routing
|
|||
{
|
||||
context.SetFeature<IRouteValues>(new RouteValues(match.Values));
|
||||
|
||||
await match.Endpoint.Invoke(context);
|
||||
return true;
|
||||
var accepted = await match.Endpoint.Send(context);
|
||||
if (accepted)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,6 @@ namespace Microsoft.AspNet.Routing
|
|||
{
|
||||
public interface IRouteEndpoint
|
||||
{
|
||||
Task Invoke(HttpContext context);
|
||||
Task<bool> Send(HttpContext context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using Microsoft.AspNet.Abstractions;
|
|||
|
||||
namespace Microsoft.AspNet.Routing
|
||||
{
|
||||
public sealed class RouteContext
|
||||
public class RouteContext
|
||||
{
|
||||
public RouteContext(HttpContext context)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Routing
|
|||
/// The result of matching a route. Includes an <see cref="IRouteEndpoint"/> to invoke and an optional collection of
|
||||
/// captured values.
|
||||
/// </summary>
|
||||
public sealed class RouteMatch
|
||||
public class RouteMatch
|
||||
{
|
||||
public RouteMatch(IRouteEndpoint endpoint)
|
||||
: this(endpoint, null)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using System.Collections.Generic;
|
|||
|
||||
namespace Microsoft.AspNet.Routing
|
||||
{
|
||||
internal class RouteValues : IRouteValues
|
||||
public class RouteValues : IRouteValues
|
||||
{
|
||||
public RouteValues(IDictionary<string, object> values)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue