Branches. Requirements for Application

This topic describes how to start apply Branches service in Xafari BC Demo (Win).

Add Xafari.BC.Branches, Xafari.BC.Branches.DC, Xafari.BC.Branches.Win, Xafari.BC.Settings.Cfg modules to the required project.

Important

The simultaneous use of the Xafari.BC.Branches.DC and Xafari.BC.Branches.Xpo modules is unacceptable and can lead to errors.

To support Branches, business class must implement Xafari.BC.Branches.IBranchSupport interface. You can inherit from a base class with a ready-made implementation of this interface. Xafari provides such classes for DC and for XPO technologies: Xafari.BC.Branches.BranchSupport and Xafari.BC.XPO.XafariBaseObject.

The code snippet below shows BranchSupport1 Domain Component that inherit from Xafari.BC.Branches.BranchSupport type. This is enough to provide Branches for the BranchSupport1:

  • c#
  • VB

using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Model;
using DevExpress.Persistent.Base;
using Xafari.BC.Branches;
using Xafari.BC;
using Xafari.BC.Branches.DC;
using Xafari.XF;
[DomainComponent]
[RegisterEntity]
public interface BranchSupport1 : BranchSupport
{
}

Imports DevExpress.ExpressApp.DC
Imports DevExpress.ExpressApp.Model
Imports DevExpress.Persistent.Base
Imports Xafari.BC.Branches
Imports Xafari.BC
Imports Xafari.BC.Branches.DC
Imports Xafari.XF
<DomainComponent> _
<RegisterEntity> _
Public Interface BranchSupport1
  Inherits BranchSupport
End Interface

Another way is that the developer can explicitly implement the Xafari.BC.Branches.IBranchSupport interface. The following code snippet demonstrates SomeDC class that implements IBranchSupport interface:

  • c#
  • VB

using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Model;
using DevExpress.Persistent.Base;
using Xafari.BC.DC;
[DomainComponent]
[NonPersistentDc]
public interface SomeDC : IBranchSupport
{
  [ModelDefault("AllowEdit", "false")]
  [VisibleInDetailView(false)]
  string BranchCode { get; set; }
}
[DomainLogic(typeof(BranchSupport))]
public class SomeDCLogic : Xafari.BC.DC.DomainLogicBase<SomeDC>
{
  public SomeDCLogic(SomeDC instance)
    : base(instance)
  {
  }
  public void AfterConstruction(SomeDC instance)
  {
    if (BranchesManager.Instance == null)
      return;
    // If the object was created when the Branches was active,
    // it is required to initialize BranchCode field.
    // Use base implementation for this
    this.ObjectSpace.Xafari().Branches().InitBranch(instance);
  }
  // Method to change Branch
  public void ChangeBranch(string branchCode)
  {
    if (BranchesManager.Instance == null)
      return;
    //Use base implementation
    this.ObjectSpace.Xafari().Branches().ChangeBranch(this.Instance, branchCode);
  }
}

Imports DevExpress.ExpressApp.DC
Imports DevExpress.ExpressApp.Model
Imports DevExpress.Persistent.Base
Imports Xafari.BC.DC
<DomainComponent> _
<NonPersistentDc> _
Public Interface SomeDC
  Inherits IBranchSupport
  <ModelDefault("AllowEdit", "false")> _
<VisibleInDetailView(False)> _
Property BranchCode As String
End Interface
<DomainLogic(GetType(BranchSupport))> _
Public Class SomeDCLogic
  Inherits Xafari.BC.DC.DomainLogicBase(Of SomeDC)
  Public Sub New(ByVal instance As SomeDC)
    MyBase.New(instance)
  End Sub
  Public Sub AfterConstruction(ByVal instance As SomeDC)
    If BranchesManager.Instance Is Nothing Then
      Return
    End If
    ' If the object was created when the Branches was active,
    ' it is required to initialize BranchCode field.
    ' Use base implementation for this
    Me.ObjectSpace.Xafari().Branches().InitBranch(instance)
  End Sub
  ' Method to change Branch
  Public Sub ChangeBranch(ByVal branchCode As String)
    If BranchesManager.Instance Is Nothing Then
      Return
    End If
    'Use base implementation
    Me.ObjectSpace.Xafari().Branches().ChangeBranch(Me.Instance, branchCode)
  End Sub
End Class

Note

It is possible that IBranchSupport implementation is inherited feature of your class, but you want to cancel Branches support for it. Decorate this class with Xafari.BC.Branches.ForceBranchSupportDisableAttribute and the application will disable Branches for such objects.

Branches based on the DevExpress XAF security system and for correct it is possible to use SecuredObjectSpaceProvider. Override CreateDefaultObjectSpaceProvider method of the XafApplication class in the following manner:

  • c#
  • VB

protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args)
{
  args.ObjectSpaceProvider = new SecuredObjectSpaceProvider((SecurityStrategy)this.Security, args.ConnectionString, args.Connection);
}

Protected Overrides Sub CreateDefaultObjectSpaceProvider(ByVal args As CreateCustomObjectSpaceProviderEventArgs)
  args.ObjectSpaceProvider = New SecuredObjectSpaceProvider(CType(Me.Security, SecurityStrategy), args.ConnectionString, args.Connection)
End Sub

UserType of your application must implement IUserBranches interface. Xafari framework supplies Xafari.BC.Branches.Xpo.BranchSecuritySystemUser and Xafari.Security.Strategy.DC.IDCSecuritySystemUser types which satisfy this requirement. It should be noted that IDCSecuritySystemUser expanded with the Extensions Framework mechanism.

There is more one important requirement the Security System must satisfy: it is LogonParametersType property of the Xafari.Security.XafariAuthentication class. The required value is "Xafari.Security.XafariAuthenticationLogonParameters".

Refer to the Xafari Demo Center for more information about the Security System settings, examine the Xafari.BCDemo.AppModule.BCDemoAppModule constructor.

Xafari.BC.Branches module registers and initializes the service automatically.