Xafari Service. Registration

Each service should be registered in the application before being used. To do it, call the XafariCommonService.Register() method in the module where the service is declared. It should be done in the XafApplication.SettingUp event handler or, if XafariModuleBase is used, in the XafariModuleBase.RegisterServices() overriden method.

The code below demonstrates how to register NumeratorManager and IndexNumeratorManager services.

  • c#
  • VB

protected override void RegisterServices(XafApplication application)

Protected Overrides Sub RegisterServices(ByVal application As XafApplication)
End Sub


It is impossible to use an unregistered service.

After the registration, a service object is created and saved for further usage in the XafariCommonService.Instance property.


Object of the service class is created by default. However, sometimes it may be required to create a service descendant. To do it, implement a method that creates its service object and save the delegate of this method in the XafariCommonService.CreateServiceInstance field. You can see such use cases in the Application Settings. Slices Designer topic.

After a service object is created, its virtual Setup() method is called. This method may be used to execute specific operations to initialize the service.


XafariCommonService class exposes two methods to initialize service: protected Setup() and public Initialize(). The presence of these two methods provides lazy initialization. The Setup() method is called during the XAF application setup. The main objective of this method is to connect the service to the application. A simple initialization is recommended for the Setup() method due to the fact most elements of a XAF application are still unavailable (including Xafari Services). When the first request comes to the service object, it is supposed that the Initialize() method is called without any limitations or restrictions applied to the process initialization. Taking data from Service Model also should be performed with the help of the Initialize() method. You can found additional information about the service initialization in the Initialization and Reset section.