Services Model

Introduction

Actual requirement is to provide the customer with the ability to configure some settings of the service. Almost all sufficiently complex services needs some customization during the deployment phase. In addition, it will provide flexibility in case of changes of business processes. The Services Model is a totality of these settings available in design-time.

When using Services Model, you must consider the following statements:

  • Services Model is an extension of the Application Model.
  • It is possible to define default values for service in the Application Model in a standard way.
  • Services settings are stored in DB.
  • Xafari supplies a a specialized tool to modify Services Model, it is a Xafari Application Support.
  • To access services settings in code, use a special Services Model service.
  • Use a separate object of the Application Model to customize the Services Model.

Services Model Structure

Services Model has three layered structure which is shown in the figure below.

xafari_service_6

The first (generated) layer is used to generate nodes by means of NodeGenerators.

The second (cloned) layer contains the Application|Xafari|Services node that is cloned from the Application Model. The values of this layer are the default values for the Service Model.

Note

Cloning involves only the layers loaded from the modules of the application. The application layer itself and the user layer do not take part in this process.

The third (stored) layer loads from DB. Only the administrator of the application can modify values on this layer.

Service Settings

All services expose their settings in a special section of the Application Model: Application|Xafari|Services|<service_name>. The Application Model is extended in a standard way, see Extend and Customize the Application Model in Code.

xafari_service_7

It is possible to define default values for service settings. To do it, edit the appropriate layers of the Application Model.

Example

This paragraph describes the organization and using of settings for Numerators service.

Definition

The code snippets below shows how to define required settings and extend Application Model with corresponding node.

Service settings are defined in the IModelServicesNumerators interface:

  • c#
  • VB

public interface IModelXafariServicesNumerators
{
  IModelServicesNumerators Numerators { get; }
}
public interface IModelServicesNumerators : IModelNode, IModelList<IModelServicesNumerator>
{
  string DefaultTemplate { get; set; }
  string DefaultKeyTemplate { get; set; }
  int DefaultStartValue { get; set; }
  int DefaultStep { get; set; }
  UseDeletedNumbersModes DefaultUseDeletedNumbers { get; set; }
  bool DefaultThroughNumeration { get; set; }
  ApplyNumeratorsStrategy DefaultApplyStrategy { get; set; }
  bool AutoApply { get; set; }
}

Public Interface IModelXafariServicesNumerators
  ReadOnly Property Numerators As IModelServicesNumerators
End Interface
Public Interface IModelServicesNumerators
  Inherits IModelNode, IModelList(Of IModelServicesNumerator)
  Property DefaultTemplate As String
  Property DefaultKeyTemplate As String
  Property DefaultStartValue As Integer
  Property DefaultStep As Integer
  Property DefaultUseDeletedNumbers As UseDeletedNumbersModes
  Property DefaultThroughNumeration As Boolean
  Property DefaultApplyStrategy As ApplyNumeratorsStrategy
  Property AutoApply As Boolean
End Interface

ExtendModelInterfaces method registers an extension of the Application Model from a module class:

  • c#
  • VB

public override void ExtendModelInterfaces(ModelInterfaceExtenders extenders)
{
  base.ExtendModelInterfaces(extenders);
  extenders.Add<IModelXafariServicesModel, IModelXafariServicesNumerators>();
}

Public Overrides Sub ExtendModelInterfaces(ByVal extenders As ModelInterfaceExtenders)
  MyBase.ExtendModelInterfaces(extenders)
  extenders.Add(Of IModelXafariServicesModel, IModelXafariServicesNumerators)()
End Sub

Applying

When the service operates, it is required to access its settings. This feature is provided by the special ServicesManager service which exposes ServicesModel property to reffer to the Application|Xafari|Services  node from the Services Model.

The code snippet below shows the implementation of the NumeratorManager.Model property and how this property is applied in the InitializeCore() method.

  • c#
  • VB

public IModelServicesNumerators Model
{
  get
  {
    return ServicesModelService.Instance.Model.Numerators();
  }
}
protected override void InitializeCore()
{
  this.AutoApply = this.Model.AutoApply;
}

Public ReadOnly Property Model As IModelServicesNumerators
  Get
    Return ServicesModelService.Instance.Model.Numerators()
  End Get
End Property
Protected Overrides Sub InitializeCore()
  Me.AutoApply = Me.Model.AutoApply
End Sub

Editing

The possibility to edit settings at runtime is implemented in the Xafari.BC.Numerators.Cfg module. The module contains class shells for the Service Model nodes. This module may be used as a part of the XAS that provides end-user (or rather admin) with access to edit settings.

The image below shows the View intended to edit the Numerators service settings. New entries are marked with bold font, as well as modified values of the stored layer.

xafari_service_8