Skip to main content
.NET 6.0+

ValueManager Class

Represents an auxiliary class used to initializes value managers.

Namespace: DevExpress.Persistent.Base

Assembly: DevExpress.ExpressApp.v23.2.dll

NuGet Package: DevExpress.ExpressApp

Declaration

public class ValueManager

Remarks

A common task in a business application is to store temporary data accessible from any part of the application on a per-user basis. This task is solved differently under different platforms. For example, in a Windows Forms application, you would use static variables, while in an ASP.NET Web Forms application, you would store the required data in session variables. In the context of the XAF, this means that you would have to implement the business logic in two platform-specific ways, for instance, via two platform-specific Controllers. The concept of value managers allows you to overcome this limitation, and have only one platform-independent Controller.

Value managers are instantiated via the ValueManager.GetValueManager<ValueType> method. This method initializes platform-specific value managers. So, the type of a value manager initialized via this method will be different in ASP.NET Web Forms and Windows Forms applications. A value manager is an object which implements the IValueManager<ValueType> interface, and so has the Value property. This property returns a previously assigned value if it is available (use the CanManageValue property to check if a value is available).

The following example demonstates how to store a string value separately for each user in a Module, ViewController, or another appropriate class:

using DevExpress.ExpressApp;
using DevExpress.Persistent.Base;

namespace MySolutionName.Module.Controllers {
    public class MyViewController : ViewController {
        protected override void OnActivated() {
            MyValue = "MyString"; // Store a value in ValueManager
            string myString = MyValue; // Get a value from ValueManager
        }
        public string MyValue {
            get {
                IValueManager<string> valueManager = ValueManager.GetValueManager<string>("myKey");
                if (valueManager.CanManageValue)
                    return valueManager.Value;
                else return "Some default value";
            }
            set {
                IValueManager<string> valueManager = ValueManager.GetValueManager<string>("myKey");
                if (valueManager.CanManageValue)
                    valueManager.Value = value;
            }
        }
    }
}

When the demonstrated code is used in a Windows Forms application, a value manager will store the MyValue in a regular property. In an ASP.NET Web Forms application, HttpSessionState will be used instead.

Inheritance

Object
ValueManager
See Also