Back to Devexpress

ValueManager Class

expressappframework-devexpress-dot-persistent-dot-base-30cbdbfc.md

latest3.6 KB
Original Source

ValueManager Class

An auxiliary class used to initialize value managers.

Namespace : DevExpress.Persistent.Base

Assembly : DevExpress.ExpressApp.v25.2.dll

NuGet Package : DevExpress.ExpressApp

Declaration

csharp
public class ValueManager
vb
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, static properties may be suitable, while in Blazor values need to be stored separately for each user. 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. The type of a value manager initialized via this method will be different in ASP.NET Core Blazor 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 demonstrates how to store a string value separately for each user in a Module, ViewController, or another appropriate class:

csharp
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;
            }
        }
    }
}

Inheritance

Object ValueManager

See Also

ValueManager Members

How to save an application's settings at runtime and then access them via a common interface from Windows Forms module

DevExpress.Persistent.Base Namespace