This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
/
ActionContext.cs
139 lines (126 loc) · 4.71 KB
/
ActionContext.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// 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.AspNet.Http;
using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Routing;
namespace Microsoft.AspNet.Mvc
{
/// <summary>
/// Context object for execution of action which has been selected as part of an HTTP request.
/// </summary>
public class ActionContext
{
/// <summary>
/// Creates an empty <see cref="ActionContext"/>.
/// </summary>
/// <remarks>
/// The default constructor is provided for unit test purposes only.
/// </remarks>
public ActionContext()
{
ModelState = new ModelStateDictionary();
}
/// <summary>
/// Creates a new <see cref="ActionContext"/>.
/// </summary>
/// <param name="actionContext">The <see cref="ActionContext"/> to copy.</param>
public ActionContext(ActionContext actionContext)
: this(
actionContext.HttpContext,
actionContext.RouteData,
actionContext.ActionDescriptor,
actionContext.ModelState)
{
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
}
/// <summary>
/// Creates a new <see cref="ActionContext"/>.
/// </summary>
/// <param name="httpContext">The <see cref="Http.HttpContext"/> for the current request.</param>
/// <param name="routeData">The <see cref="AspNet.Routing.RouteData"/> for the current request.</param>
/// <param name="actionDescriptor">The <see cref="Abstractions.ActionDescriptor"/> for the selected action.</param>
public ActionContext(
HttpContext httpContext,
RouteData routeData,
ActionDescriptor actionDescriptor)
: this(httpContext, routeData, actionDescriptor, new ModelStateDictionary())
{
}
/// <summary>
/// Creates a new <see cref="ActionContext"/>.
/// </summary>
/// <param name="httpContext">The <see cref="Http.HttpContext"/> for the current request.</param>
/// <param name="routeData">The <see cref="AspNet.Routing.RouteData"/> for the current request.</param>
/// <param name="actionDescriptor">The <see cref="Abstractions.ActionDescriptor"/> for the selected action.</param>
/// <param name="modelState">The <see cref="ModelStateDictionary"/>.</param>
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;
}
/// <summary>
/// Gets or sets the <see cref="Abstractions.ActionDescriptor"/> for the selected action.
/// </summary>
/// <remarks>
/// The property setter is provided for unit test purposes only.
/// </remarks>
public ActionDescriptor ActionDescriptor
{
get; set;
}
/// <summary>
/// Gets or sets the <see cref="Http.HttpContext"/> for the current request.
/// </summary>
/// <remarks>
/// The property setter is provided for unit test purposes only.
/// </remarks>
public HttpContext HttpContext
{
get; set;
}
/// <summary>
/// Gets the <see cref="ModelStateDictionary"/>.
/// </summary>
public ModelStateDictionary ModelState
{
get;
}
/// <summary>
/// Gets or sets the <see cref="AspNet.Routing.RouteData"/> for the current request.
/// </summary>
/// <remarks>
/// The property setter is provided for unit test purposes only.
/// </remarks>
public RouteData RouteData
{
get; set;
}
}
}