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