Adds ActionContext to OperationBindingContext

This change makes it possible to access the ActionContext/ActionDescriptor
from inside of modelbinding.
This commit is contained in:
Ryan Nowak 2015-11-25 14:05:38 -08:00
parent 31e42ee312
commit 0832365ec2
21 changed files with 154 additions and 105 deletions

View File

@ -15,9 +15,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public class OperationBindingContext public class OperationBindingContext
{ {
/// <summary> /// <summary>
/// Gets or sets the <see cref="HttpContext"/> for the current request. /// Gets or sets the <see cref="Mvc.ActionContext"/> for the current request.
/// </summary> /// </summary>
public HttpContext HttpContext { get; set; } public ActionContext ActionContext { get; set; }
/// <summary>
/// Gets the <see cref="Http.HttpContext"/> for the current request.
/// </summary>
public HttpContext HttpContext => ActionContext.HttpContext;
/// <summary> /// <summary>
/// Gets or sets the set of <see cref="IInputFormatter"/> instances associated with this context. /// Gets or sets the set of <see cref="IInputFormatter"/> instances associated with this context.

View File

@ -224,11 +224,11 @@ namespace Microsoft.AspNet.Mvc.Controllers
{ {
return new OperationBindingContext return new OperationBindingContext
{ {
ActionContext = context,
InputFormatters = context.InputFormatters, InputFormatters = context.InputFormatters,
ModelBinder = new CompositeModelBinder(context.ModelBinders), ModelBinder = new CompositeModelBinder(context.ModelBinders),
ValidatorProvider = new CompositeModelValidatorProvider(context.ValidatorProviders), ValidatorProvider = new CompositeModelValidatorProvider(context.ValidatorProviders),
MetadataProvider = _modelMetadataProvider, MetadataProvider = _modelMetadataProvider,
HttpContext = context.HttpContext,
ValueProvider = new CompositeValueProvider(context.ValueProviders), ValueProvider = new CompositeValueProvider(context.ValueProviders),
}; };
} }

View File

@ -11,7 +11,6 @@ using System.Linq.Expressions;
using System.Reflection; using System.Reflection;
using System.Runtime.ExceptionServices; using System.Runtime.ExceptionServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Formatters; using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.AspNet.Mvc.ModelBinding.Validation; using Microsoft.AspNet.Mvc.ModelBinding.Validation;
@ -29,7 +28,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="model">The model instance to update and validate.</param> /// <param name="model">The model instance to update and validate.</param>
/// <param name="prefix">The prefix to use when looking up values in the <paramref name="valueProvider"/>. /// <param name="prefix">The prefix to use when looking up values in the <paramref name="valueProvider"/>.
/// </param> /// </param>
/// <param name="httpContext">The <see cref="HttpContext"/> for the current executing request.</param> /// <param name="actionContext">The <see cref="ActionContext"/> for the current executing request.</param>
/// <param name="modelState">The <see cref="ModelStateDictionary"/> used for maintaining state and /// <param name="modelState">The <see cref="ModelStateDictionary"/> used for maintaining state and
/// results of model-binding validation.</param> /// results of model-binding validation.</param>
/// <param name="metadataProvider">The provider used for reading metadata for the model type.</param> /// <param name="metadataProvider">The provider used for reading metadata for the model type.</param>
@ -44,16 +43,16 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// on the model instance.</param> /// on the model instance.</param>
/// <returns>A <see cref="Task"/> that on completion returns <c>true</c> if the update is successful</returns> /// <returns>A <see cref="Task"/> that on completion returns <c>true</c> if the update is successful</returns>
public static Task<bool> TryUpdateModelAsync<TModel>( public static Task<bool> TryUpdateModelAsync<TModel>(
TModel model, TModel model,
string prefix, string prefix,
HttpContext httpContext, ActionContext actionContext,
ModelStateDictionary modelState, ModelStateDictionary modelState,
IModelMetadataProvider metadataProvider, IModelMetadataProvider metadataProvider,
IModelBinder modelBinder, IModelBinder modelBinder,
IValueProvider valueProvider, IValueProvider valueProvider,
IList<IInputFormatter> inputFormatters, IList<IInputFormatter> inputFormatters,
IObjectModelValidator objectModelValidator, IObjectModelValidator objectModelValidator,
IModelValidatorProvider validatorProvider) IModelValidatorProvider validatorProvider)
where TModel : class where TModel : class
{ {
if (model == null) if (model == null)
@ -66,9 +65,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
throw new ArgumentNullException(nameof(prefix)); throw new ArgumentNullException(nameof(prefix));
} }
if (httpContext == null) if (actionContext == null)
{ {
throw new ArgumentNullException(nameof(httpContext)); throw new ArgumentNullException(nameof(actionContext));
} }
if (modelState == null) if (modelState == null)
@ -110,7 +109,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
return TryUpdateModelAsync( return TryUpdateModelAsync(
model, model,
prefix, prefix,
httpContext, actionContext,
modelState, modelState,
metadataProvider, metadataProvider,
modelBinder, modelBinder,
@ -130,7 +129,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="model">The model instance to update and validate.</param> /// <param name="model">The model instance to update and validate.</param>
/// <param name="prefix">The prefix to use when looking up values in the <paramref name="valueProvider"/>. /// <param name="prefix">The prefix to use when looking up values in the <paramref name="valueProvider"/>.
/// </param> /// </param>
/// <param name="httpContext">The <see cref="HttpContext"/> for the current executing request.</param> /// <param name="actionContext">The <see cref="ActionContext"/> for the current executing request.</param>
/// <param name="modelState">The <see cref="ModelStateDictionary"/> used for maintaining state and /// <param name="modelState">The <see cref="ModelStateDictionary"/> used for maintaining state and
/// results of model-binding validation.</param> /// results of model-binding validation.</param>
/// <param name="metadataProvider">The provider used for reading metadata for the model type.</param> /// <param name="metadataProvider">The provider used for reading metadata for the model type.</param>
@ -150,7 +149,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public static Task<bool> TryUpdateModelAsync<TModel>( public static Task<bool> TryUpdateModelAsync<TModel>(
TModel model, TModel model,
string prefix, string prefix,
HttpContext httpContext, ActionContext actionContext,
ModelStateDictionary modelState, ModelStateDictionary modelState,
IModelMetadataProvider metadataProvider, IModelMetadataProvider metadataProvider,
IModelBinder modelBinder, IModelBinder modelBinder,
@ -171,9 +170,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
throw new ArgumentNullException(nameof(prefix)); throw new ArgumentNullException(nameof(prefix));
} }
if (httpContext == null) if (actionContext == null)
{ {
throw new ArgumentNullException(nameof(httpContext)); throw new ArgumentNullException(nameof(actionContext));
} }
if (modelState == null) if (modelState == null)
@ -222,7 +221,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
return TryUpdateModelAsync( return TryUpdateModelAsync(
model, model,
prefix, prefix,
httpContext, actionContext,
modelState, modelState,
metadataProvider, metadataProvider,
modelBinder, modelBinder,
@ -242,7 +241,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="model">The model instance to update and validate.</param> /// <param name="model">The model instance to update and validate.</param>
/// <param name="prefix">The prefix to use when looking up values in the <paramref name="valueProvider"/>. /// <param name="prefix">The prefix to use when looking up values in the <paramref name="valueProvider"/>.
/// </param> /// </param>
/// <param name="httpContext">The <see cref="HttpContext"/> for the current executing request.</param> /// <param name="actionContext">The <see cref="ActionContext"/> for the current executing request.</param>
/// <param name="modelState">The <see cref="ModelStateDictionary"/> used for maintaining state and /// <param name="modelState">The <see cref="ModelStateDictionary"/> used for maintaining state and
/// results of model-binding validation.</param> /// results of model-binding validation.</param>
/// <param name="metadataProvider">The provider used for reading metadata for the model type.</param> /// <param name="metadataProvider">The provider used for reading metadata for the model type.</param>
@ -261,7 +260,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public static Task<bool> TryUpdateModelAsync<TModel>( public static Task<bool> TryUpdateModelAsync<TModel>(
TModel model, TModel model,
string prefix, string prefix,
HttpContext httpContext, ActionContext actionContext,
ModelStateDictionary modelState, ModelStateDictionary modelState,
IModelMetadataProvider metadataProvider, IModelMetadataProvider metadataProvider,
IModelBinder modelBinder, IModelBinder modelBinder,
@ -282,9 +281,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
throw new ArgumentNullException(nameof(prefix)); throw new ArgumentNullException(nameof(prefix));
} }
if (httpContext == null) if (actionContext == null)
{ {
throw new ArgumentNullException(nameof(httpContext)); throw new ArgumentNullException(nameof(actionContext));
} }
if (modelState == null) if (modelState == null)
@ -331,7 +330,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
model, model,
typeof(TModel), typeof(TModel),
prefix, prefix,
httpContext, actionContext,
modelState, modelState,
metadataProvider, metadataProvider,
modelBinder, modelBinder,
@ -351,7 +350,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="modelType">The type of model instance to update and validate.</param> /// <param name="modelType">The type of model instance to update and validate.</param>
/// <param name="prefix">The prefix to use when looking up values in the <paramref name="valueProvider"/>. /// <param name="prefix">The prefix to use when looking up values in the <paramref name="valueProvider"/>.
/// </param> /// </param>
/// <param name="httpContext">The <see cref="HttpContext"/> for the current executing request.</param> /// <param name="actionContext">The <see cref="ActionContext"/> for the current executing request.</param>
/// <param name="modelState">The <see cref="ModelStateDictionary"/> used for maintaining state and /// <param name="modelState">The <see cref="ModelStateDictionary"/> used for maintaining state and
/// results of model-binding validation.</param> /// results of model-binding validation.</param>
/// <param name="metadataProvider">The provider used for reading metadata for the model type.</param> /// <param name="metadataProvider">The provider used for reading metadata for the model type.</param>
@ -369,7 +368,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
object model, object model,
Type modelType, Type modelType,
string prefix, string prefix,
HttpContext httpContext, ActionContext actionContext,
ModelStateDictionary modelState, ModelStateDictionary modelState,
IModelMetadataProvider metadataProvider, IModelMetadataProvider metadataProvider,
IModelBinder modelBinder, IModelBinder modelBinder,
@ -393,9 +392,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
throw new ArgumentNullException(nameof(prefix)); throw new ArgumentNullException(nameof(prefix));
} }
if (httpContext == null) if (actionContext == null)
{ {
throw new ArgumentNullException(nameof(httpContext)); throw new ArgumentNullException(nameof(actionContext));
} }
if (modelState == null) if (modelState == null)
@ -438,7 +437,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
model, model,
modelType, modelType,
prefix, prefix,
httpContext, actionContext,
modelState, modelState,
metadataProvider, metadataProvider,
modelBinder, modelBinder,
@ -458,7 +457,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="modelType">The type of model instance to update and validate.</param> /// <param name="modelType">The type of model instance to update and validate.</param>
/// <param name="prefix">The prefix to use when looking up values in the <paramref name="valueProvider"/>. /// <param name="prefix">The prefix to use when looking up values in the <paramref name="valueProvider"/>.
/// </param> /// </param>
/// <param name="httpContext">The <see cref="HttpContext"/> for the current executing request.</param> /// <param name="actionContext">The <see cref="ActionContext"/> for the current executing request.</param>
/// <param name="modelState">The <see cref="ModelStateDictionary"/> used for maintaining state and /// <param name="modelState">The <see cref="ModelStateDictionary"/> used for maintaining state and
/// results of model-binding validation.</param> /// results of model-binding validation.</param>
/// <param name="metadataProvider">The provider used for reading metadata for the model type.</param> /// <param name="metadataProvider">The provider used for reading metadata for the model type.</param>
@ -478,7 +477,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
object model, object model,
Type modelType, Type modelType,
string prefix, string prefix,
HttpContext httpContext, ActionContext actionContext,
ModelStateDictionary modelState, ModelStateDictionary modelState,
IModelMetadataProvider metadataProvider, IModelMetadataProvider metadataProvider,
IModelBinder modelBinder, IModelBinder modelBinder,
@ -503,9 +502,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
throw new ArgumentNullException(nameof(prefix)); throw new ArgumentNullException(nameof(prefix));
} }
if (httpContext == null) if (actionContext == null)
{ {
throw new ArgumentNullException(nameof(httpContext)); throw new ArgumentNullException(nameof(actionContext));
} }
if (modelState == null) if (modelState == null)
@ -567,7 +566,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
ModelBinder = modelBinder, ModelBinder = modelBinder,
ValidatorProvider = validatorProvider, ValidatorProvider = validatorProvider,
MetadataProvider = metadataProvider, MetadataProvider = metadataProvider,
HttpContext = httpContext, ActionContext = actionContext,
ValueProvider = valueProvider, ValueProvider = valueProvider,
}; };

View File

@ -1446,7 +1446,7 @@ namespace Microsoft.AspNet.Mvc
return ModelBindingHelper.TryUpdateModelAsync( return ModelBindingHelper.TryUpdateModelAsync(
model, model,
prefix, prefix,
HttpContext, ControllerContext,
ModelState, ModelState,
MetadataProvider, MetadataProvider,
new CompositeModelBinder(ControllerContext.ModelBinders), new CompositeModelBinder(ControllerContext.ModelBinders),
@ -1487,7 +1487,7 @@ namespace Microsoft.AspNet.Mvc
return ModelBindingHelper.TryUpdateModelAsync( return ModelBindingHelper.TryUpdateModelAsync(
model, model,
prefix, prefix,
HttpContext, ControllerContext,
ModelState, ModelState,
MetadataProvider, MetadataProvider,
new CompositeModelBinder(ControllerContext.ModelBinders), new CompositeModelBinder(ControllerContext.ModelBinders),
@ -1528,7 +1528,7 @@ namespace Microsoft.AspNet.Mvc
return ModelBindingHelper.TryUpdateModelAsync( return ModelBindingHelper.TryUpdateModelAsync(
model, model,
prefix, prefix,
HttpContext, ControllerContext,
ModelState, ModelState,
MetadataProvider, MetadataProvider,
new CompositeModelBinder(ControllerContext.ModelBinders), new CompositeModelBinder(ControllerContext.ModelBinders),
@ -1577,7 +1577,7 @@ namespace Microsoft.AspNet.Mvc
return ModelBindingHelper.TryUpdateModelAsync( return ModelBindingHelper.TryUpdateModelAsync(
model, model,
prefix, prefix,
HttpContext, ControllerContext,
ModelState, ModelState,
MetadataProvider, MetadataProvider,
new CompositeModelBinder(ControllerContext.ModelBinders), new CompositeModelBinder(ControllerContext.ModelBinders),
@ -1625,7 +1625,7 @@ namespace Microsoft.AspNet.Mvc
return ModelBindingHelper.TryUpdateModelAsync( return ModelBindingHelper.TryUpdateModelAsync(
model, model,
prefix, prefix,
HttpContext, ControllerContext,
ModelState, ModelState,
MetadataProvider, MetadataProvider,
new CompositeModelBinder(ControllerContext.ModelBinders), new CompositeModelBinder(ControllerContext.ModelBinders),
@ -1665,7 +1665,7 @@ namespace Microsoft.AspNet.Mvc
model, model,
modelType, modelType,
prefix, prefix,
HttpContext, ControllerContext,
ModelState, ModelState,
MetadataProvider, MetadataProvider,
new CompositeModelBinder(ControllerContext.ModelBinders), new CompositeModelBinder(ControllerContext.ModelBinders),
@ -1718,7 +1718,7 @@ namespace Microsoft.AspNet.Mvc
model, model,
modelType, modelType,
prefix, prefix,
HttpContext, ControllerContext,
ModelState, ModelState,
MetadataProvider, MetadataProvider,
new CompositeModelBinder(ControllerContext.ModelBinders), new CompositeModelBinder(ControllerContext.ModelBinders),

View File

@ -76,7 +76,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
var context = new ModelBindingContext(); var context = new ModelBindingContext();
context.OperationBindingContext = new OperationBindingContext() context.OperationBindingContext = new OperationBindingContext()
{ {
HttpContext = new DefaultHttpContext(), ActionContext = new ActionContext()
{
HttpContext = new DefaultHttpContext(),
},
}; };
var services = new Mock<IServiceProvider>(); var services = new Mock<IServiceProvider>();
@ -100,7 +103,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
var context = new ModelBindingContext(); var context = new ModelBindingContext();
context.OperationBindingContext = new OperationBindingContext() context.OperationBindingContext = new OperationBindingContext()
{ {
HttpContext = new DefaultHttpContext(), ActionContext = new ActionContext()
{
HttpContext = new DefaultHttpContext(),
},
}; };
var services = new Mock<IServiceProvider>(MockBehavior.Strict); var services = new Mock<IServiceProvider>(MockBehavior.Strict);

View File

@ -209,7 +209,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
{ {
OperationBindingContext = new OperationBindingContext() OperationBindingContext = new OperationBindingContext()
{ {
HttpContext = new DefaultHttpContext(), ActionContext = new ActionContext()
{
HttpContext = new DefaultHttpContext(),
},
MetadataProvider = new TestModelMetadataProvider(), MetadataProvider = new TestModelMetadataProvider(),
} }
}; };

View File

@ -94,8 +94,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
var operationBindingContext = new OperationBindingContext var operationBindingContext = new OperationBindingContext
{ {
ActionContext = new ActionContext()
{
HttpContext = new DefaultHttpContext(),
},
MetadataProvider = metadataProvider, MetadataProvider = metadataProvider,
HttpContext = new DefaultHttpContext(),
ValidatorProvider = Mock.Of<IModelValidatorProvider>(), ValidatorProvider = Mock.Of<IModelValidatorProvider>(),
}; };

View File

@ -256,10 +256,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
var operationBindingContext = new OperationBindingContext var operationBindingContext = new OperationBindingContext
{ {
ActionContext = new ActionContext()
{
HttpContext = httpContext,
},
InputFormatters = inputFormatters.ToList(), InputFormatters = inputFormatters.ToList(),
ModelBinder = new BodyModelBinder(new TestHttpRequestStreamReaderFactory()), ModelBinder = new BodyModelBinder(new TestHttpRequestStreamReaderFactory()),
MetadataProvider = metadataProvider, MetadataProvider = metadataProvider,
HttpContext = httpContext,
}; };
var bindingContext = new ModelBindingContext var bindingContext = new ModelBindingContext

View File

@ -54,9 +54,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
ValueProvider = new SimpleValueProvider(), ValueProvider = new SimpleValueProvider(),
OperationBindingContext = new OperationBindingContext OperationBindingContext = new OperationBindingContext
{ {
ActionContext = new ActionContext()
{
HttpContext = new DefaultHttpContext(),
},
ModelBinder = new CancellationTokenModelBinder(), ModelBinder = new CancellationTokenModelBinder(),
MetadataProvider = metadataProvider, MetadataProvider = metadataProvider,
HttpContext = new DefaultHttpContext(),
} }
}; };

View File

@ -426,7 +426,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
{ {
OperationBindingContext = new OperationBindingContext() OperationBindingContext = new OperationBindingContext()
{ {
HttpContext = new DefaultHttpContext(), ActionContext = new ActionContext()
{
HttpContext = new DefaultHttpContext(),
},
MetadataProvider = new TestModelMetadataProvider(), MetadataProvider = new TestModelMetadataProvider(),
} }
}; };

View File

@ -416,7 +416,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
ModelState = new ModelStateDictionary(), ModelState = new ModelStateDictionary(),
OperationBindingContext = new OperationBindingContext() OperationBindingContext = new OperationBindingContext()
{ {
HttpContext = new DefaultHttpContext(), ActionContext = new ActionContext()
{
HttpContext = new DefaultHttpContext(),
},
MetadataProvider = new TestModelMetadataProvider(), MetadataProvider = new TestModelMetadataProvider(),
}, },
ValidationState = new ValidationStateDictionary(), ValidationState = new ValidationStateDictionary(),

View File

@ -125,9 +125,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
ModelName = "file", ModelName = "file",
OperationBindingContext = new OperationBindingContext OperationBindingContext = new OperationBindingContext
{ {
ActionContext = new ActionContext()
{
HttpContext = httpContext,
},
ModelBinder = new FormCollectionModelBinder(), ModelBinder = new FormCollectionModelBinder(),
MetadataProvider = metadataProvider, MetadataProvider = metadataProvider,
HttpContext = httpContext,
}, },
ValidationState = new ValidationStateDictionary(), ValidationState = new ValidationStateDictionary(),
}; };

View File

@ -221,9 +221,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
ModelState = new ModelStateDictionary(), ModelState = new ModelStateDictionary(),
OperationBindingContext = new OperationBindingContext OperationBindingContext = new OperationBindingContext
{ {
ActionContext = new ActionContext()
{
HttpContext = httpContext,
},
ModelBinder = new FormFileModelBinder(), ModelBinder = new FormFileModelBinder(),
MetadataProvider = metadataProvider, MetadataProvider = metadataProvider,
HttpContext = httpContext,
}, },
ValidationState = new ValidationStateDictionary(), ValidationState = new ValidationStateDictionary(),
}; };

View File

@ -129,9 +129,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
ModelState = new ModelStateDictionary(), ModelState = new ModelStateDictionary(),
OperationBindingContext = new OperationBindingContext OperationBindingContext = new OperationBindingContext
{ {
ActionContext = new ActionContext()
{
HttpContext = new DefaultHttpContext(),
},
ModelBinder = new HeaderModelBinder(), ModelBinder = new HeaderModelBinder(),
MetadataProvider = metadataProvider, MetadataProvider = metadataProvider,
HttpContext = new DefaultHttpContext()
}, },
BinderModelName = modelMetadata.BinderModelName, BinderModelName = modelMetadata.BinderModelName,
BindingSource = modelMetadata.BindingSource, BindingSource = modelMetadata.BindingSource,

View File

@ -200,7 +200,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Test
{ {
OperationBindingContext = new OperationBindingContext() OperationBindingContext = new OperationBindingContext()
{ {
HttpContext = new DefaultHttpContext(), ActionContext = new ActionContext()
{
HttpContext = new DefaultHttpContext(),
},
MetadataProvider = new TestModelMetadataProvider(), MetadataProvider = new TestModelMetadataProvider(),
ModelBinder = new SimpleTypeModelBinder(), ModelBinder = new SimpleTypeModelBinder(),
}, },

View File

@ -8,7 +8,7 @@ using System.ComponentModel.DataAnnotations;
using System.Globalization; using System.Globalization;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Internal;
using Microsoft.AspNet.Mvc.Formatters; using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.AspNet.Mvc.ModelBinding.Validation; using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Moq; using Moq;
@ -46,7 +46,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
var result = await ModelBindingHelper.TryUpdateModelAsync( var result = await ModelBindingHelper.TryUpdateModelAsync(
model, model,
string.Empty, string.Empty,
Mock.Of<HttpContext>(), new ActionContext() { HttpContext = new DefaultHttpContext() },
new ModelStateDictionary(), new ModelStateDictionary(),
metadataProvider, metadataProvider,
GetCompositeBinder(binder.Object), GetCompositeBinder(binder.Object),
@ -88,7 +88,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
var result = await ModelBindingHelper.TryUpdateModelAsync( var result = await ModelBindingHelper.TryUpdateModelAsync(
model, model,
"", "",
Mock.Of<HttpContext>(), new ActionContext() { HttpContext = new DefaultHttpContext() },
modelStateDictionary, modelStateDictionary,
modelMetadataProvider, modelMetadataProvider,
GetCompositeBinder(binders), GetCompositeBinder(binders),
@ -130,7 +130,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
var result = await ModelBindingHelper.TryUpdateModelAsync( var result = await ModelBindingHelper.TryUpdateModelAsync(
model, model,
"", "",
Mock.Of<HttpContext>(), new ActionContext() { HttpContext = new DefaultHttpContext() },
modelStateDictionary, modelStateDictionary,
metadataProvider, metadataProvider,
GetCompositeBinder(binders), GetCompositeBinder(binders),
@ -162,7 +162,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
var result = await ModelBindingHelper.TryUpdateModelAsync( var result = await ModelBindingHelper.TryUpdateModelAsync(
model, model,
string.Empty, string.Empty,
Mock.Of<HttpContext>(), new ActionContext() { HttpContext = new DefaultHttpContext() },
new ModelStateDictionary(), new ModelStateDictionary(),
metadataProvider, metadataProvider,
GetCompositeBinder(binder.Object), GetCompositeBinder(binder.Object),
@ -218,7 +218,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
var result = await ModelBindingHelper.TryUpdateModelAsync( var result = await ModelBindingHelper.TryUpdateModelAsync(
model, model,
"", "",
Mock.Of<HttpContext>(), new ActionContext() { HttpContext = new DefaultHttpContext() },
modelStateDictionary, modelStateDictionary,
metadataProvider, metadataProvider,
GetCompositeBinder(binders), GetCompositeBinder(binders),
@ -252,7 +252,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
var result = await ModelBindingHelper.TryUpdateModelAsync( var result = await ModelBindingHelper.TryUpdateModelAsync(
model, model,
string.Empty, string.Empty,
Mock.Of<HttpContext>(), new ActionContext() { HttpContext = new DefaultHttpContext() },
new ModelStateDictionary(), new ModelStateDictionary(),
metadataProvider, metadataProvider,
GetCompositeBinder(binder.Object), GetCompositeBinder(binder.Object),
@ -305,7 +305,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
var result = await ModelBindingHelper.TryUpdateModelAsync( var result = await ModelBindingHelper.TryUpdateModelAsync(
model, model,
"", "",
Mock.Of<HttpContext>(), new ActionContext() { HttpContext = new DefaultHttpContext() },
modelStateDictionary, modelStateDictionary,
TestModelMetadataProvider.CreateDefaultProvider(), TestModelMetadataProvider.CreateDefaultProvider(),
GetCompositeBinder(binders), GetCompositeBinder(binders),
@ -359,7 +359,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
var result = await ModelBindingHelper.TryUpdateModelAsync( var result = await ModelBindingHelper.TryUpdateModelAsync(
model, model,
"", "",
Mock.Of<HttpContext>(), new ActionContext() { HttpContext = new DefaultHttpContext() },
modelStateDictionary, modelStateDictionary,
metadataProvider, metadataProvider,
GetCompositeBinder(binders), GetCompositeBinder(binders),
@ -514,7 +514,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
model, model,
model.GetType(), model.GetType(),
prefix: "", prefix: "",
httpContext: Mock.Of<HttpContext>(), actionContext: new ActionContext() { HttpContext = new DefaultHttpContext() },
modelState: new ModelStateDictionary(), modelState: new ModelStateDictionary(),
metadataProvider: metadataProvider, metadataProvider: metadataProvider,
modelBinder: GetCompositeBinder(binder.Object), modelBinder: GetCompositeBinder(binder.Object),
@ -570,20 +570,20 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
// Act // Act
var result = await ModelBindingHelper.TryUpdateModelAsync( var result = await ModelBindingHelper.TryUpdateModelAsync(
model, model,
model.GetType(), model.GetType(),
"", "",
Mock.Of<HttpContext>(), new ActionContext() { HttpContext = new DefaultHttpContext() },
modelStateDictionary, modelStateDictionary,
metadataProvider, metadataProvider,
GetCompositeBinder(binders), GetCompositeBinder(binders),
valueProvider, valueProvider,
new List<IInputFormatter>(), new List<IInputFormatter>(),
new DefaultObjectValidator( new DefaultObjectValidator(
new IExcludeTypeValidationFilter[0], new IExcludeTypeValidationFilter[0],
metadataProvider), metadataProvider),
validator, validator,
includePredicate); includePredicate);
// Assert // Assert
Assert.True(result); Assert.True(result);
@ -610,7 +610,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
model, model,
modelType: model.GetType(), modelType: model.GetType(),
prefix: "", prefix: "",
httpContext: Mock.Of<HttpContext>(), actionContext: new ActionContext() { HttpContext = new DefaultHttpContext() },
modelState: new ModelStateDictionary(), modelState: new ModelStateDictionary(),
metadataProvider: metadataProvider, metadataProvider: metadataProvider,
modelBinder: GetCompositeBinder(binder.Object), modelBinder: GetCompositeBinder(binder.Object),
@ -649,19 +649,19 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
// Act // Act
var result = await ModelBindingHelper.TryUpdateModelAsync( var result = await ModelBindingHelper.TryUpdateModelAsync(
model, model,
model.GetType(), model.GetType(),
"", "",
Mock.Of<HttpContext>(), new ActionContext() { HttpContext = new DefaultHttpContext() },
modelStateDictionary, modelStateDictionary,
TestModelMetadataProvider.CreateDefaultProvider(), TestModelMetadataProvider.CreateDefaultProvider(),
GetCompositeBinder(binders), GetCompositeBinder(binders),
valueProvider, valueProvider,
new List<IInputFormatter>(), new List<IInputFormatter>(),
new DefaultObjectValidator( new DefaultObjectValidator(
new IExcludeTypeValidationFilter[0], new IExcludeTypeValidationFilter[0],
metadataProvider), metadataProvider),
validator); validator);
// Assert // Assert
Assert.True(result); Assert.True(result);
@ -687,7 +687,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
model, model,
typeof(User), typeof(User),
"", "",
Mock.Of<HttpContext>(), new ActionContext() { HttpContext = new DefaultHttpContext() },
new ModelStateDictionary(), new ModelStateDictionary(),
metadataProvider, metadataProvider,
GetCompositeBinder(binder.Object), GetCompositeBinder(binder.Object),

View File

@ -681,9 +681,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
ModelMetadata = GetMetadataForType(typeof(TypeWithExcludedPropertiesUsingBindAttribute)), ModelMetadata = GetMetadataForType(typeof(TypeWithExcludedPropertiesUsingBindAttribute)),
OperationBindingContext = new OperationBindingContext OperationBindingContext = new OperationBindingContext
{ {
HttpContext = new DefaultHttpContext ActionContext = new ActionContext()
{ {
RequestServices = CreateServices() HttpContext = new DefaultHttpContext()
{
RequestServices = CreateServices(),
},
}, },
ValidatorProvider = Mock.Of<IModelValidatorProvider>(), ValidatorProvider = Mock.Of<IModelValidatorProvider>(),
MetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(), MetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(),

View File

@ -88,12 +88,15 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
ModelState = new ModelStateDictionary(), ModelState = new ModelStateDictionary(),
OperationBindingContext = new OperationBindingContext OperationBindingContext = new OperationBindingContext
{ {
ActionContext = new ActionContext()
{
HttpContext = new DefaultHttpContext()
{
RequestServices = services.BuildServiceProvider(),
}
},
ModelBinder = new HeaderModelBinder(), ModelBinder = new HeaderModelBinder(),
MetadataProvider = metadataProvider, MetadataProvider = metadataProvider,
HttpContext = new DefaultHttpContext()
{
RequestServices = services.BuildServiceProvider(),
},
}, },
BinderModelName = modelMetadata.BinderModelName, BinderModelName = modelMetadata.BinderModelName,
BindingSource = modelMetadata.BindingSource, BindingSource = modelMetadata.BindingSource,

View File

@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
return new OperationBindingContext() return new OperationBindingContext()
{ {
HttpContext = httpContext, ActionContext = controllerContext,
InputFormatters = controllerContext.InputFormatters, InputFormatters = controllerContext.InputFormatters,
MetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(), MetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(),
ValidatorProvider = new CompositeModelValidatorProvider(controllerContext.ValidatorProviders), ValidatorProvider = new CompositeModelValidatorProvider(controllerContext.ValidatorProviders),

View File

@ -1105,7 +1105,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
model, model,
model.GetType(), model.GetType(),
prefix, prefix,
operationContext.HttpContext, operationContext.ActionContext,
modelState, modelState,
operationContext.MetadataProvider, operationContext.MetadataProvider,
operationContext.ModelBinder, operationContext.ModelBinder,

View File

@ -61,7 +61,10 @@ namespace Microsoft.AspNet.Mvc.WebApiCompatShim
ModelName = "someName", ModelName = "someName",
OperationBindingContext = new OperationBindingContext OperationBindingContext = new OperationBindingContext
{ {
HttpContext = new DefaultHttpContext(), ActionContext = new ActionContext()
{
HttpContext = new DefaultHttpContext(),
},
MetadataProvider = metadataProvider, MetadataProvider = metadataProvider,
}, },
ValidationState = new ValidationStateDictionary(), ValidationState = new ValidationStateDictionary(),