2010-06-21 Marek Habersack <mhabersack@novell.com>
[mcs.git] / class / System.Web.Mvc / System.Web.Mvc / ControllerBase.cs
blob8d6de638044758b6f50bda65d89040352b88b3a7
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 {
14 using System;
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 {
27 get;
28 set;
31 [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly",
32 Justification = "This property is settable so that unit tests can provide mock implementations.")]
33 public TempDataDictionary TempData {
34 get {
35 if (_tempDataDictionary == null) {
36 _tempDataDictionary = new TempDataDictionary();
38 return _tempDataDictionary;
40 set {
41 _tempDataDictionary = value;
45 public bool ValidateRequest {
46 get {
47 return _validateRequest;
49 set {
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 {
57 get {
58 if (_valueProvider == null) {
59 _valueProvider = new ValueProviderDictionary(ControllerContext);
61 return _valueProvider;
63 set {
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 {
71 get {
72 if (_viewDataDictionary == null) {
73 _viewDataDictionary = new ViewDataDictionary();
75 return _viewDataDictionary;
77 set {
78 _viewDataDictionary = value;
82 protected virtual void Execute(RequestContext requestContext) {
83 if (requestContext == null) {
84 throw new ArgumentNullException("requestContext");
87 Initialize(requestContext);
88 ExecuteCore();
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);
101 #endregion