Xafari Context Service. Activation and Deactivation

The service's context object can be deactivated when needed. The activity of the context object is synchronized with the activity of the service itself (see Xafari Common Service. Activation and Deactivation). The deactivation of the service causes the deactivation of all context objects of the service. The activity of the context object is indicated by the ServiceSpaceContextBase. Active property of the BoolList type.

By default, a context object activates right after its initialization.

Note

When implementing a context service, the developer should constantly watch the activity state of the context object during executing significant operations. It is recommended to avoid events generating when trying to execute methods of deactivated service object.

The Xafari.Utils.ActiveScope object is intended to perform a local deactivation of a context service. The code example below demonstrates its usage.

  • example

protected override void ActiveScope(){
 using (var objectSpace = this.Application.CreateObjectSpace())
 {
  using (objectSpace.Xafari().Numerators().ActiveScope(false))
  {
          // any code
          objectSpace.CommitChanges();
  }
 }
 }