// 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.ModelBinding; namespace Microsoft.AspNetCore.Mvc { /// /// The context associated with the current request for a controller. /// public class ControllerContext : ActionContext { private IList _valueProviderFactories; /// /// 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 IList ValueProviderFactories { get { if (_valueProviderFactories == null) { _valueProviderFactories = new List(); } return _valueProviderFactories; } set { if (value == null) { throw new ArgumentNullException(nameof(value)); } _valueProviderFactories = value; } } } }