1
/* ****************************************************************************
3 * Copyright (c) Microsoft Corporation. All rights reserved.
5 * This software is subject to the Microsoft Public License (Ms-PL).
6 * A copy of the license can be found in the license.htm file included
7 * in this distribution.
9 * You must not remove this notice, or any other, from this software.
11 * ***************************************************************************/
13 namespace System
.Web
.Mvc
{
15 using System
.Collections
.Generic
;
16 using System
.Diagnostics
.CodeAnalysis
;
17 using System
.Web
.Routing
;
19 public abstract class ControllerBase
: MarshalByRefObject
, IController
{
21 private TempDataDictionary _tempDataDictionary
;
22 private bool _validateRequest
= true;
23 private IDictionary
<string, ValueProviderResult
> _valueProvider
;
24 private ViewDataDictionary _viewDataDictionary
;
26 public ControllerContext ControllerContext
{
31 [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly",
32 Justification
= "This property is settable so that unit tests can provide mock implementations.")]
33 public TempDataDictionary TempData
{
35 if (_tempDataDictionary
== null) {
36 _tempDataDictionary
= new TempDataDictionary();
38 return _tempDataDictionary
;
41 _tempDataDictionary
= value;
45 public bool ValidateRequest
{
47 return _validateRequest
;
50 _validateRequest
= value;
54 [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly",
55 Justification
= "This property is settable so that unit tests can provide mock implementations.")]
56 public IDictionary
<string, ValueProviderResult
> ValueProvider
{
58 if (_valueProvider
== null) {
59 _valueProvider
= new ValueProviderDictionary(ControllerContext
);
61 return _valueProvider
;
64 _valueProvider
= value;
68 [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly",
69 Justification
= "This property is settable so that unit tests can provide mock implementations.")]
70 public ViewDataDictionary ViewData
{
72 if (_viewDataDictionary
== null) {
73 _viewDataDictionary
= new ViewDataDictionary();
75 return _viewDataDictionary
;
78 _viewDataDictionary
= value;
82 protected virtual void Execute(RequestContext requestContext
) {
83 if (requestContext
== null) {
84 throw new ArgumentNullException("requestContext");
87 Initialize(requestContext
);
91 protected abstract void ExecuteCore();
93 protected virtual void Initialize(RequestContext requestContext
) {
94 ControllerContext
= new ControllerContext(requestContext
, this);
97 #region IController Members
98 void IController
.Execute(RequestContext requestContext
) {
99 Execute(requestContext
);