Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.

Commit d10682d

Browse files
committed
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
1 parent 1d4ceef commit d10682d

File tree

7 files changed

+56
-19
lines changed

7 files changed

+56
-19
lines changed

samples/RoutingSample.Web/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ await context
1818
.HttpContext
1919
.Response
2020
.WriteAsync(
21-
"match1, route values -" + context.Values.Print()));
21+
"match1, route values -" + context.RouteData.Values.Print()));
2222

2323
var endpoint2 = new DelegateRouteEndpoint(async (context) =>
2424
await context

src/Microsoft.AspNet.Routing/Microsoft.AspNet.Routing.kproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<Compile Include="RouteConstraintBuilder.cs" />
4242
<Compile Include="RouteConstraintMatcher.cs" />
4343
<Compile Include="RouteContext.cs" />
44+
<Compile Include="RouteData.cs" />
4445
<Compile Include="RouteDirection.cs" />
4546
<Compile Include="RouterMiddleware.cs" />
4647
<Compile Include="RouteValueDictionary.cs" />
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System.Collections.Generic;
54
using Microsoft.AspNet.Http;
5+
using System;
66

77
namespace Microsoft.AspNet.Routing
88
{
99
public class RouteContext
1010
{
11+
private RouteData _routeData;
12+
1113
public RouteContext(HttpContext httpContext)
1214
{
1315
HttpContext = httpContext;
1416

1517
RequestPath = httpContext.Request.Path.Value;
18+
RouteData = new RouteData();
1619
}
1720

1821
public HttpContext HttpContext { get; private set; }
@@ -21,8 +24,21 @@ public RouteContext(HttpContext httpContext)
2124

2225
public string RequestPath { get; private set; }
2326

24-
public IRouter Router { get; set; }
25-
26-
public IDictionary<string, object> Values { get; set; }
27+
public RouteData RouteData
28+
{
29+
get
30+
{
31+
return _routeData;
32+
}
33+
set
34+
{
35+
if (value == null)
36+
{
37+
throw new ArgumentNullException("value");
38+
}
39+
40+
_routeData = value;
41+
}
42+
}
2743
}
2844
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Collections.Generic;
5+
6+
namespace Microsoft.AspNet.Routing
7+
{
8+
/// <summary>
9+
/// Summary description for RouteData
10+
/// </summary>
11+
public class RouteData
12+
{
13+
public RouteData()
14+
{
15+
Routers = new Stack<IRouter>();
16+
}
17+
18+
public Stack<IRouter> Routers { get; private set; }
19+
20+
public IDictionary<string, object> Values { get; set; }
21+
}
22+
}

src/Microsoft.AspNet.Routing/RouterMiddleware.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System.Threading.Tasks;
54
using Microsoft.AspNet.Http;
65
using Microsoft.AspNet.Routing;
6+
using System.Threading.Tasks;
77

88
namespace Microsoft.AspNet.Builder
99
{
@@ -29,10 +29,8 @@ private RequestDelegate Next
2929

3030
public async Task Invoke(HttpContext httpContext)
3131
{
32-
var context = new RouteContext(httpContext)
33-
{
34-
Router = Router,
35-
};
32+
var context = new RouteContext(httpContext);
33+
context.RouteData.Routers.Push(Router);
3634

3735
await Router.RouteAsync(context);
3836
if (!context.IsHandled)

src/Microsoft.AspNet.Routing/Template/TemplateRoute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public async virtual Task RouteAsync([NotNull] RouteContext context)
8888
else
8989
{
9090
// Not currently doing anything to clean this up if it's not a match. Consider hardening this.
91-
context.Values = values;
91+
context.RouteData.Values = values;
9292

9393
if (RouteConstraintMatcher.Match(Constraints,
9494
values,

test/Microsoft.AspNet.Routing.Tests/Template/TemplateRouteTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public async void Match_Success_LeadingSlash()
3232

3333
// Assert
3434
Assert.True(context.IsHandled);
35-
Assert.Equal(2, context.Values.Count);
36-
Assert.Equal("Home", context.Values["controller"]);
37-
Assert.Equal("Index", context.Values["action"]);
35+
Assert.Equal(2, context.RouteData.Values.Count);
36+
Assert.Equal("Home", context.RouteData.Values["controller"]);
37+
Assert.Equal("Index", context.RouteData.Values["action"]);
3838
}
3939

4040
[Fact]
@@ -49,7 +49,7 @@ public async void Match_Success_RootUrl()
4949

5050
// Assert
5151
Assert.True(context.IsHandled);
52-
Assert.Equal(0, context.Values.Count);
52+
Assert.Equal(0, context.RouteData.Values.Count);
5353
}
5454

5555
[Fact]
@@ -64,9 +64,9 @@ public async void Match_Success_Defaults()
6464

6565
// Assert
6666
Assert.True(context.IsHandled);
67-
Assert.Equal(2, context.Values.Count);
68-
Assert.Equal("Home", context.Values["controller"]);
69-
Assert.Equal("Index", context.Values["action"]);
67+
Assert.Equal(2, context.RouteData.Values.Count);
68+
Assert.Equal("Home", context.RouteData.Values["controller"]);
69+
Assert.Equal("Index", context.RouteData.Values["action"]);
7070
}
7171

7272
[Fact]
@@ -97,7 +97,7 @@ public async void Match_RejectedByHandler()
9797
Assert.False(context.IsHandled);
9898

9999
// Issue #16 tracks this.
100-
Assert.NotNull(context.Values);
100+
Assert.NotNull(context.RouteData.Values);
101101
}
102102

103103
private static RouteContext CreateRouteContext(string requestPath)

0 commit comments

Comments
 (0)