-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
…ific context.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ internal async Task<List<TElement>> BindSimpleCollection(ModelBindingContext bin | |
{ | ||
var innerBindingContext = new ModelBindingContext(bindingContext) | ||
{ | ||
ModelMetadata = bindingContext.MetadataProvider.GetMetadataForType(null, typeof(TElement)), | ||
ModelMetadata = bindingContext.OperationBindingContext.MetadataProvider.GetMetadataForType(null, typeof(TElement)), | ||
ModelName = bindingContext.ModelName, | ||
ValueProvider = new CompositeValueProvider | ||
{ | ||
|
@@ -60,7 +60,7 @@ internal async Task<List<TElement>> BindSimpleCollection(ModelBindingContext bin | |
}; | ||
|
||
object boundValue = null; | ||
if (await bindingContext.ModelBinder.BindModelAsync(innerBindingContext)) | ||
if (await bindingContext.OperationBindingContext.ModelBinder.BindModelAsync(innerBindingContext)) | ||
{ | ||
boundValue = innerBindingContext.Model; | ||
bindingContext.ValidationNode.ChildNodes.Add(innerBindingContext.ValidationNode); | ||
|
@@ -101,7 +101,7 @@ internal async Task<List<TElement>> BindComplexCollectionFromIndexes(ModelBindin | |
var fullChildName = ModelBindingHelper.CreateIndexModelName(bindingContext.ModelName, indexName); | ||
var childBindingContext = new ModelBindingContext(bindingContext) | ||
This comment has been minimized.
Sorry, something went wrong.
rynowak
Member
|
||
{ | ||
ModelMetadata = bindingContext.MetadataProvider.GetMetadataForType(null, typeof(TElement)), | ||
ModelMetadata = bindingContext.OperationBindingContext.MetadataProvider.GetMetadataForType(null, typeof(TElement)), | ||
ModelName = fullChildName | ||
}; | ||
|
||
|
@@ -110,7 +110,7 @@ internal async Task<List<TElement>> BindComplexCollectionFromIndexes(ModelBindin | |
|
||
var modelType = bindingContext.ModelType; | ||
|
||
if (await bindingContext.ModelBinder.BindModelAsync(childBindingContext)) | ||
if (await bindingContext.OperationBindingContext.ModelBinder.BindModelAsync(childBindingContext)) | ||
{ | ||
didBind = true; | ||
boundValue = childBindingContext.Model; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,8 +80,8 @@ public virtual async Task<bool> BindModelAsync([NotNull] ModelBindingContext bin | |
bindingContext.ModelName); | ||
} | ||
|
||
var validationContext = new ModelValidationContext(bindingContext.MetadataProvider, | ||
bindingContext.ValidatorProvider, | ||
var validationContext = new ModelValidationContext( bindingContext.OperationBindingContext.MetadataProvider, | ||
bindingContext.OperationBindingContext.ValidatorProvider, | ||
bindingContext.ModelState, | ||
bindingContext.ModelMetadata, | ||
containerMetadata: null); | ||
|
@@ -131,11 +131,7 @@ private static ModelBindingContext CreateNewBindingContext(ModelBindingContext o | |
ModelName = modelName, | ||
ModelState = oldBindingContext.ModelState, | ||
ValueProvider = oldBindingContext.ValueProvider, | ||
OriginalValueProvider = oldBindingContext.OriginalValueProvider, | ||
ValidatorProvider = oldBindingContext.ValidatorProvider, | ||
MetadataProvider = oldBindingContext.MetadataProvider, | ||
ModelBinder = oldBindingContext.ModelBinder, | ||
HttpContext = oldBindingContext.HttpContext, | ||
OperationBindingContext = oldBindingContext.OperationBindingContext, | ||
PropertyFilter = oldBindingContext.PropertyFilter, | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
harshgMSFT
Author
Contributor
|
||
}; | ||
|
||
|
@@ -155,7 +151,7 @@ private static ModelBindingContext CreateNewBindingContext(ModelBindingContext o | |
// of all value providers. This is so that every artifact that is explicitly marked using an | ||
// IValueProviderMetadata can restrict model binding to only use value providers which support this | ||
// IValueProviderMetadata. | ||
var valueProvider = oldBindingContext.OriginalValueProvider as IMetadataAwareValueProvider; | ||
var valueProvider = oldBindingContext.OperationBindingContext.OriginalValueProvider as IMetadataAwareValueProvider; | ||
if (valueProvider != null) | ||
{ | ||
newBindingContext.ValueProvider = valueProvider.Filter(metadata); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// 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.Http; | ||
|
||
namespace Microsoft.AspNet.Mvc.ModelBinding | ||
{ | ||
/// <summary> | ||
/// A context that contains operating information for model binding and validation. | ||
/// </summary> | ||
public class OperationBindingContext | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="OperationBindingContext"/> class. | ||
/// </summary> | ||
public OperationBindingContext() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="OperationBindingContext"/> class using the | ||
/// <param name="bindingContext" />. | ||
// </summary> | ||
/// <remarks> | ||
/// This constructor copies certain values that won't change between parent and child objects, | ||
/// e.g. ValueProvider, ModelState | ||
/// </remarks> | ||
public OperationBindingContext(OperationBindingContext bindingContext) | ||
{ | ||
if (bindingContext != null) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
harshgMSFT
Author
Contributor
|
||
{ | ||
OriginalValueProvider = bindingContext.OriginalValueProvider; | ||
MetadataProvider = bindingContext.MetadataProvider; | ||
ModelBinder = bindingContext.ModelBinder; | ||
ValidatorProvider = bindingContext.ValidatorProvider; | ||
HttpContext = bindingContext.HttpContext; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the <see cref="HttpContext"/> for the current request. | ||
/// </summary> | ||
public HttpContext HttpContext { get; set; } | ||
|
||
/// <summary> | ||
/// Gets unaltered value provider collection. | ||
/// Value providers can be filtered by specific model binders. | ||
/// </summary> | ||
public IValueProvider OriginalValueProvider { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the <see cref="IModelBinder"/> associated with this context. | ||
/// </summary> | ||
public IModelBinder ModelBinder { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the <see cref="IModelMetadataProvider"/> associated with this context. | ||
/// </summary> | ||
public IModelMetadataProvider MetadataProvider { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the <see cref="IModelValidatorProvider"/> instance used for model validation with this | ||
/// context. | ||
/// </summary> | ||
public IModelValidatorProvider ValidatorProvider { get; set; } | ||
} | ||
} |
Can this just be
ValueProvider
?