Dynamic Properties. Getting Started

To use Dynamic Properties, it is required to add a number of platform-agnostic and platform-specific modules, these are listed below:

  • Platform-agnostic: XafariBCModule, XafariBCXpoModule or XafariBCDCModule;
  • Win-specific: XafariBCWinModule, XafariEditorsWinModule, ValidationWindowsFormsModule;
  • ASP.NET-specific: XafariBCWebModule, XafariEditorsWebModule, ValidationAspNetModule.

Important

ASP.NET application also requires a references to the Xafari.Web and Xafari.Web.Utils. Another requirement is to inherit from the Xafari.Web.XafariWebApplication or modify WebApplication constructor as follows:

  • c#
  • VB

public Solution3AspNetApplication()
{
  InitializeComponent();
  if (HttpContext.Current != null)
    ValueManager.ValueManagerType = typeof(ASPSessionAndThreadsValueManager<>).GetGenericTypeDefinition();
}

Public Sub New()
  InitializeComponent()
  If HttpContext.Current IsNot Nothing Then
    ValueManager.ValueManagerType = GetType(ASPSessionAndThreadsValueManager(Of )).GetGenericTypeDefinition()
  End If
End Sub

The simplest way to support Dynamic Properties in business class is inherit from the base entities that already implements such a feature.

In general, you should implement IInstancePropertiesSupport interface.

dynamic_properties_4

The class diagram above is implemented for XPO and Domain Components, in both cases, there are persistent and non persistent implementation.


Xafari.BC.Xpo Module

Xafari.BC.DC Module

IInstancePropertiesSupport

XafariBaseObject (abstract)

DynamicObjectBase

NonPersistentXafariBaseObject

PersistentDynamicObject

PersistentXafariBaseObject

XafariObject

IInstanceProperty

InstancePropertyBase (abstract)

DynamicPropertyBase

XpoNonPersistentDynamicProperty

PersistentDynamicProperty

XpoPersistentDynamicProperty


To access Dynamic Properties use IInstancePropertiesSupport interface.

DynamicPropertiesObject

Xafari.BC.DynamicProperties.DynamicPropertiesObject class provides the basic features for working with Dynamic Properties. Use DynamicPropertiesObject to obtain a special non persistent class with a dynamic set of properties.

CreateObject and CreateObject<T> methods

These methods require to pay attention to the optional parameter key of the System.Object type. The fact that the modification of DynamicPropertiesList collection entails the  regeneration of DynamicPropertiesObject, modification of the Type and (or) Name fields for the elements of this collection has the same effects. Therefore, by default, when generating DynamicPropertiesObject objects on the basis of the properties collection a special key must be computed. Thus, the framework can decide whether regenerate DynamicPropertiesObject or it can use an existing instance. The object will be generated again in the following cases:

  • change the number of items in the DynamicPropertiesList collection;
  • For one ore more elements of the DynamicPropertiesList collection the Name and (or) Type field was modified;
  • CreateObject or CreateObject <T> method receives not null value for key parameter;
  • DynamicPropertiesObject object with the same key already exists in the dictionary.

CreateDetailView method

The method returns Detail View for DynamicPropertiesObject instance. The method is used in Xafari editors, that display a list of Dynamic Properties. modelHandler parameter of Action<IModel Detail View> type allows to customise the displaying of Dynamic Properties.