// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; namespace Microsoft.AspNetCore.Mvc { /// /// The context associated with the current request for a controller. /// public class ControllerContext : ActionContext { private FormatterCollection _inputFormatters; private IList _modelBinders; private IList _validatorProviders; private IList _valueProviders; /// /// Creates a new . /// /// /// The default constructor is provided for unit test purposes only. /// public ControllerContext() : base() { } /// /// Creates a new . /// /// The associated with the current request. public ControllerContext(ActionContext context) : base(context) { if (!(context.ActionDescriptor is ControllerActionDescriptor)) { throw new ArgumentException(Resources.FormatActionDescriptorMustBeBasedOnControllerAction( typeof(ControllerActionDescriptor)), nameof(context)); } } /// /// Gets or sets the associated with the current request. /// public new ControllerActionDescriptor ActionDescriptor { get { return (ControllerActionDescriptor)base.ActionDescriptor; } set { base.ActionDescriptor = value; } } /// /// Gets or sets the list of instances for the current request. /// public virtual FormatterCollection InputFormatters { get { if (_inputFormatters == null) { _inputFormatters = new FormatterCollection(); } return _inputFormatters; } set { if (value == null) { throw new ArgumentNullException(nameof(value)); } _inputFormatters = value; } } /// /// Gets or sets the list of instances for the current request. /// public virtual IList ModelBinders { get { if (_modelBinders == null) { _modelBinders = new List(); } return _modelBinders; } set { if (value == null) { throw new ArgumentNullException(nameof(value)); } _modelBinders = value; } } /// /// Gets or sets the list of instances for the current request. /// public virtual IList ValidatorProviders { get { if (_validatorProviders == null) { _validatorProviders = new List(); } return _validatorProviders; } set { if (value == null) { throw new ArgumentNullException(nameof(value)); } _validatorProviders = value; } } /// /// Gets or sets the list of instances for the current request. /// public virtual IList ValueProviders { get { if (_valueProviders == null) { _valueProviders = new List(); } return _valueProviders; } set { if (value == null) { throw new ArgumentNullException(nameof(value)); } _valueProviders = value; } } } }