forked from aspnet/Mvc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a context class for ValueProviderFactories
This allows model binding to once again be independent of routing. Sending RouteContext into model binding was an odd choice from a layering point-of-view.
- Loading branch information
Showing
10 changed files
with
48 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
src/Microsoft.AspNet.Mvc.ModelBinding/ValueProviders/IValueProviderFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
// 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 Microsoft.AspNet.Routing; | ||
|
||
namespace Microsoft.AspNet.Mvc.ModelBinding | ||
{ | ||
public interface IValueProviderFactory | ||
{ | ||
/// <summary> | ||
/// Get a value provider with values from the given <paramref name="requestContext"/>. | ||
/// </summary> | ||
/// <param name="routeContext">RouteContext that value provider will populate from</param> | ||
/// <param name="context">ValueProviderFactoryContext that value provider will populate from</param> | ||
/// <returns>a value provider instance or null</returns> | ||
IValueProvider GetValueProvider([NotNull] RouteContext routeContext); | ||
IValueProvider GetValueProvider([NotNull] ValueProviderFactoryContext context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
src/Microsoft.AspNet.Mvc.ModelBinding/ValueProviders/RouteValueValueProviderFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
// 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 Microsoft.AspNet.Routing; | ||
|
||
namespace Microsoft.AspNet.Mvc.ModelBinding | ||
{ | ||
public class RouteValueValueProviderFactory : IValueProviderFactory | ||
{ | ||
public IValueProvider GetValueProvider([NotNull] RouteContext routeContext) | ||
public IValueProvider GetValueProvider([NotNull] ValueProviderFactoryContext context) | ||
{ | ||
return new DictionaryBasedValueProvider(routeContext.RouteData.Values); | ||
return new DictionaryBasedValueProvider(context.RouteValues); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Microsoft.AspNet.Mvc.ModelBinding/ValueProviders/ValueProviderFactoryContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 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; | ||
|
||
namespace Microsoft.AspNet.Mvc.ModelBinding | ||
{ | ||
public class ValueProviderFactoryContext | ||
{ | ||
public ValueProviderFactoryContext( | ||
[NotNull] HttpContext httpContext, | ||
[NotNull] IDictionary<string, object> routeValues) | ||
{ | ||
HttpContext = httpContext; | ||
RouteValues = routeValues; | ||
} | ||
|
||
public HttpContext HttpContext { get; private set; } | ||
|
||
public IDictionary<string, object> RouteValues { get; private set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters