Xafari Logic Controller | Xafari Framework

Typically, a business object of enterprise application is accompanied by a large number of View controllers. These controllers are implementing some specific functionality of the entity. Often it is the handlers of the following events:

  • OnDeactivated;
  • OnActivated;
  • OnViewControlsCreated.

The handlers, in turn, are subscribed to other events, and thus implement some logic, when these events occur. When using a significant amount of View controllers, there are certain difficulties:

  • When the form of the persistent object opens, all instances of ViewController will be created.
  • All forms in the application will open slowly because it takes the time to create a large number of View Controllers.
  • When you open a form, excessive consumption of RAM occurs as a large number of View Controllers are loaded into the memory.

The problem with a large number of View Controllers can be solved using Logic Controllers. Logic Controllers occupy an intermediate position between the business object and View Controllers. Instead of using a set of View Controllers, you are encouraged to use set of Logic Controllers, In order to handle events, all Logic Controllers require only one View Controller.

Such behavior can be implemented using the special service and View Controller. Service shall register Logic Controllers and manage their set, and a special View Controller routes occurred events to Logic Controllers associated with some type.


Let's become familiar with LogicControllerSample solution. To use Logic Controller execute the following steps:

Add Xafari Module to LogicControllersSample.Module.

Implement EmployeeLogicController class derived from LogicControllerBase< T >. The following code demonstrates this.

To register Logic Controllers, override Setup method as follows.

As you can see, we use LogicControllerService static class. Register method receives two parameters:

  • Logic Controller type
  • delegate returns an instance of the specified type.

Demonstration of work

Now you can build the application and start debugging. Add Employee object.

logic controller

Let’s examine Trace records when Employee List View opens:

Open-Close Employee Detail View and see Trace:

CallStack contains:

I.e. the methods is called by a special controller supplied with Xafari. Thus, it is possible to control the behavior of the object via the events using only one View Controller. Logic Controllers should be divided according to their intended use.