Issue aspnet/Mvc#56 - merging RouteContext and RequestContext

This is the routing part of these changes, and just the breaking changes
parts.

Follow-ups will add:
- DataTokens
- Tracking the logical stack of routers
This commit is contained in:
Ryan Nowak 2014-06-04 13:24:01 -07:00
parent 1d4ceef81b
commit d10682d15b
7 changed files with 55 additions and 18 deletions

View File

@ -18,7 +18,7 @@ namespace RoutingSample.Web
.HttpContext
.Response
.WriteAsync(
"match1, route values -" + context.Values.Print()));
"match1, route values -" + context.RouteData.Values.Print()));
var endpoint2 = new DelegateRouteEndpoint(async (context) =>
await context

View File

@ -41,6 +41,7 @@
<Compile Include="RouteConstraintBuilder.cs" />
<Compile Include="RouteConstraintMatcher.cs" />
<Compile Include="RouteContext.cs" />
<Compile Include="RouteData.cs" />
<Compile Include="RouteDirection.cs" />
<Compile Include="RouterMiddleware.cs" />
<Compile Include="RouteValueDictionary.cs" />

View File

@ -1,18 +1,21 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using Microsoft.AspNet.Http;
using System;
namespace Microsoft.AspNet.Routing
{
public class RouteContext
{
private RouteData _routeData;
public RouteContext(HttpContext httpContext)
{
HttpContext = httpContext;
RequestPath = httpContext.Request.Path.Value;
RouteData = new RouteData();
}
public HttpContext HttpContext { get; private set; }
@ -21,8 +24,21 @@ namespace Microsoft.AspNet.Routing
public string RequestPath { get; private set; }
public IRouter Router { get; set; }
public RouteData RouteData
{
get
{
return _routeData;
}
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
public IDictionary<string, object> Values { get; set; }
_routeData = value;
}
}
}
}

View File

@ -0,0 +1,22 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
namespace Microsoft.AspNet.Routing
{
/// <summary>
/// Summary description for RouteData
/// </summary>
public class RouteData
{
public RouteData()
{
Routers = new Stack<IRouter>();
}
public Stack<IRouter> Routers { get; private set; }
public IDictionary<string, object> Values { get; set; }
}
}

View File

@ -1,9 +1,9 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Routing;
using System.Threading.Tasks;
namespace Microsoft.AspNet.Builder
{
@ -29,10 +29,8 @@ namespace Microsoft.AspNet.Builder
public async Task Invoke(HttpContext httpContext)
{
var context = new RouteContext(httpContext)
{
Router = Router,
};
var context = new RouteContext(httpContext);
context.RouteData.Routers.Push(Router);
await Router.RouteAsync(context);
if (!context.IsHandled)

View File

@ -88,7 +88,7 @@ namespace Microsoft.AspNet.Routing.Template
else
{
// Not currently doing anything to clean this up if it's not a match. Consider hardening this.
context.Values = values;
context.RouteData.Values = values;
if (RouteConstraintMatcher.Match(Constraints,
values,

View File

@ -32,9 +32,9 @@ namespace Microsoft.AspNet.Routing.Template.Tests
// Assert
Assert.True(context.IsHandled);
Assert.Equal(2, context.Values.Count);
Assert.Equal("Home", context.Values["controller"]);
Assert.Equal("Index", context.Values["action"]);
Assert.Equal(2, context.RouteData.Values.Count);
Assert.Equal("Home", context.RouteData.Values["controller"]);
Assert.Equal("Index", context.RouteData.Values["action"]);
}
[Fact]
@ -49,7 +49,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests
// Assert
Assert.True(context.IsHandled);
Assert.Equal(0, context.Values.Count);
Assert.Equal(0, context.RouteData.Values.Count);
}
[Fact]
@ -64,9 +64,9 @@ namespace Microsoft.AspNet.Routing.Template.Tests
// Assert
Assert.True(context.IsHandled);
Assert.Equal(2, context.Values.Count);
Assert.Equal("Home", context.Values["controller"]);
Assert.Equal("Index", context.Values["action"]);
Assert.Equal(2, context.RouteData.Values.Count);
Assert.Equal("Home", context.RouteData.Values["controller"]);
Assert.Equal("Index", context.RouteData.Values["action"]);
}
[Fact]
@ -97,7 +97,7 @@ namespace Microsoft.AspNet.Routing.Template.Tests
Assert.False(context.IsHandled);
// Issue #16 tracks this.
Assert.NotNull(context.Values);
Assert.NotNull(context.RouteData.Values);
}
private static RouteContext CreateRouteContext(string requestPath)