Logic Controllers. Getting Started

The module, which contains the Logic Controller class should be the heir of the Xafari.BC.XafariModuleBase (instead of DevExpress.ExpressApp.ModuleBase). Be sure to refer to the Xafari.BC.dll assembly (Xafari BC Module).

Custom Logic Controller class is the descendant of the LogicControllerBase or one of its heirs. The recommended approach - this is the inheritance from the LogicControllerBase<T>, where the T - the type of business entity (similar to a standard TargetObjectType of XAF Controller). Another useful variant - it is the inheritance from the LogicControllerBase<T, TView>, where TView indicates the type of View, for which the Controller will be activated.

Logic Controller class exposes a number of members, completely similar to the standard View Controller, i.e. names, designation and signatures match completely. TargetType, TypeOfView, TargetViewId, TargetViewNesting properties specifies a View, for which a Logic Controller is activated (similar to the TargetObjectType).

The code snippet below implements EmployeeLogicController class:

  • c#
  • VB

using Xafari.BC.LogicControllers;
namespace LogicControllersSample.Module.LogicControllers
{
  public class EmployeeLogicController : LogicControllerBase<Employee>
  {
    protected override void OnDeactivated()
    {
      ShowLogicWork("OnDeactivated");
    }
    protected override void OnActivated()
    {
      ShowLogicWork("OnActivated");
    }
    protected override void OnViewControlsCreated()
    {
      ShowLogicWork("OnViewControlsCreated");
    }
    protected override void DisposeCore()
    {
      ShowLogicWork("Dispose");
      base.DisposeCore();
    }
    private void ShowLogicWork(string msg)
    {
      Tracing.Tracer.LogValue("EmployeeLogicController", msg);
    }
  }
}

Imports Xafari.BC.LogicControllers
Namespace LogicControllersSample.Module.LogicControllers
  Public Class EmployeeLogicController
    Inherits LogicControllerBase(Of Employee)
    Protected Overrides Sub OnDeactivated()
      ShowLogicWork("OnDeactivated")
    End Sub
    Protected Overrides Sub OnActivated()
      ShowLogicWork("OnActivated")
    End Sub
    Protected Overrides Sub OnViewControlsCreated()
      ShowLogicWork("OnViewControlsCreated")
    End Sub
    Protected Overrides Sub DisposeCore()
      ShowLogicWork("Dispose")
      MyBase.DisposeCore()
    End Sub
    Private Sub ShowLogicWork(ByVal msg As String)
      Tracing.Tracer.LogValue("EmployeeLogicController", msg)
    End Sub
  End Class
End Namespace

To apply Logic Controller successfully, it is required to register it. If the Logic Controller's class  is implemented in the module, derived from XafariModuleBase, this ensures correct registration. The system, using the Reflection registers and applies it automatically.

Note:

There is a way to speed up the loading of the app. This should modify the module class that contains Logic Controllers: override GetLogicControllerTypes() method and returns the set of required Logic Controllers. The following code snippet demonstrates this technique:

  • c#
  • VB

using Xafari.BC;
using Xafari.BC.LogicControllers;
namespace LogicControllersSample.Module
{
  public sealed partial class LogicControllersSampleModule : XafariModuleBase
  {
    public LogicControllersSampleModule()
    {
      InitializeComponent();
    }
    protected override IEnumerable<Type> GetLogicControllerTypes()
    {
      return new [] { typeof(EmployeeLogicController), typeof(EmployeeTwoLogicController), typeof(Employee2LogicController) };
    }
  }
}

Imports Xafari.BC
Imports Xafari.BC.LogicControllers
Namespace LogicControllersSample.Module
  Public Partial NotInheritable Class LogicControllersSampleModule
    Inherits XafariModuleBase
    Public Sub New()
      InitializeComponent()
    End Sub
    Protected Overrides Function GetLogicControllerTypes() As IEnumerable(Of Type)
      Return New () { GetType(EmployeeLogicController),GetType(EmployeeTwoLogicController),GetType(Employee2LogicController) }
    End Function
  End Class
End Namespace