summaryrefslogtreecommitdiff
path: root/external/aspnetwebstack/src/System.Web.Http/Controllers/HttpActionContext.cs
blob: be461e7437f4fbd6344f72604803744ebc6dc8af (plain)
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
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Net.Http;
using System.Web.Http.ModelBinding;

namespace System.Web.Http.Controllers
{
    /// <summary>
    /// Contains information for the executing action.
    /// </summary>
    public class HttpActionContext
    {
        private readonly ModelStateDictionary _modelState = new ModelStateDictionary();
        private readonly Dictionary<string, object> _operationArguments = new Dictionary<string, object>();
        private HttpActionDescriptor _actionDescriptor;
        private HttpControllerContext _controllerContext;
       
        public HttpActionContext(HttpControllerContext controllerContext, HttpActionDescriptor actionDescriptor)
        {
            if (controllerContext == null)
            {
                throw Error.ArgumentNull("controllerContext");
            }

            if (actionDescriptor == null)
            {
                throw Error.ArgumentNull("actionDescriptor");
            }

            _controllerContext = controllerContext;
            _actionDescriptor = actionDescriptor;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="HttpActionContext"/> class.
        /// </summary>
        /// <remarks>The default constructor is intended for use by unit testing only.</remarks>
        public HttpActionContext()
        {
        }

        public HttpControllerContext ControllerContext
        {
            get { return _controllerContext; }
            set
            {
                if (value == null)
                {
                    throw Error.PropertyNull();
                }

                _controllerContext = value;
            }
        }

        public HttpActionDescriptor ActionDescriptor
        {
            get { return _actionDescriptor; }
            set
            {
                if (value == null)
                {
                    throw Error.PropertyNull();
                }

                _actionDescriptor = value;
            }
        }

        public ModelStateDictionary ModelState
        {
            get { return _modelState; }
        }

        public Dictionary<string, object> ActionArguments
        {
            get { return _operationArguments; }
        }

        public HttpResponseMessage Response { get; set; }

        /// <summary>
        /// Gets the current <see cref="HttpRequestMessage"/>.
        /// </summary>
        public HttpRequestMessage Request
        {
            get { return _controllerContext != null ? _controllerContext.Request : null; }
        }
    }
}