// 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 Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Routing;
namespace Microsoft.AspNetCore.Mvc
{
///
/// Context object for execution of action which has been selected as part of an HTTP request.
///
public class ActionContext
{
///
/// Creates an empty .
///
///
/// The default constructor is provided for unit test purposes only.
///
public ActionContext()
{
ModelState = new ModelStateDictionary();
}
///
/// Creates a new .
///
/// The to copy.
public ActionContext(ActionContext actionContext)
: this(
actionContext.HttpContext,
actionContext.RouteData,
actionContext.ActionDescriptor,
actionContext.ModelState)
{
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
}
///
/// Creates a new .
///
/// The for the current request.
/// The for the current request.
/// The for the selected action.
public ActionContext(
HttpContext httpContext,
RouteData routeData,
ActionDescriptor actionDescriptor)
: this(httpContext, routeData, actionDescriptor, new ModelStateDictionary())
{
}
///
/// Creates a new .
///
/// The for the current request.
/// The for the current request.
/// The for the selected action.
/// The .
public ActionContext(
HttpContext httpContext,
RouteData routeData,
ActionDescriptor actionDescriptor,
ModelStateDictionary modelState)
{
if (httpContext == null)
{
throw new ArgumentNullException(nameof(httpContext));
}
if (routeData == null)
{
throw new ArgumentNullException(nameof(routeData));
}
if (actionDescriptor == null)
{
throw new ArgumentNullException(nameof(actionDescriptor));
}
if (modelState == null)
{
throw new ArgumentNullException(nameof(modelState));
}
HttpContext = httpContext;
RouteData = routeData;
ActionDescriptor = actionDescriptor;
ModelState = modelState;
}
///
/// Gets or sets the for the selected action.
///
///
/// The property setter is provided for unit test purposes only.
///
public ActionDescriptor ActionDescriptor
{
get; set;
}
///
/// Gets or sets the for the current request.
///
///
/// The property setter is provided for unit test purposes only.
///
public HttpContext HttpContext
{
get; set;
}
///
/// Gets the .
///
public ModelStateDictionary ModelState
{
get;
}
///
/// Gets or sets the for the current request.
///
///
/// The property setter is provided for unit test purposes only.
///
public RouteData RouteData
{
get; set;
}
}
}