Business Operations. Implementation Class

The Business Operation class only describes the outer interface of the BO (i.e. its parameters). The business logic of the BO resides in the Business Operation Implementation class (or classes). Any BO can have one or several Implementations. It is possible to select any Implementation as the default one.

The BO Implementation class should implement the IOperationService interface. The base implementation of the interface is available in the OperationServiceBase abstract class. It is recommended to inherit it when programming one's own BO Implementations.

The code sample below demonstrates the Implementation class for the context-sensitive list BO described in the Business Operations Class topic.

  • c#
  • VB

/// <summary>
/// Implementation of the business operation for changing the freight cost.
/// </summary>
[DisplayName("Default implementation")]
[Description("Changes the freight cost based on the specified percent value.")]
public class ChangeFreightContextDefaultImpl : OperationServiceBase
  public override void Execute(IBusinessOperation businessOperation)
    var bo = (ChangeFreightContext)businessOperation;
    var rate = (decimal)(bo.Percent / 100);
    using (var objectSpace = BusinessOperationManager.Instance.Application.CreateObjectSpace())
      foreach (var rawOrder in bo.Orders)
        var order = objectSpace.GetObject(rawOrder); //Document in current ObjectSpace.
        order.Freight = order.Freight + (order.Freight * rate);
        var oldFreight = order.Freight;
        var msg = string.Format("Order # {0}. Previous freight cost {1}, new {2}", order.Number, oldFreight, order.Freight);

''' <summary>
''' Implementation of the business operation for changing the freight cost.
''' </summary>
<BusinessOperation(GetType(ChangeFreightContext))> _
<DisplayName("Default implementation")> _
<Description("Changes the freight cost based on the specified percent value.")> _
Public Class ChangeFreightContextDefaultImpl
  Inherits OperationServiceBase
  Public Overrides Sub Execute(ByVal businessOperation As IBusinessOperation)
    Dim bo = CType(businessOperation, ChangeFreightContext)
    Dim rate = CType((bo.Percent / 100), decimal)
    Using objectSpace = BusinessOperationManager.Instance.Application.CreateObjectSpace()
      For Each rawOrder In bo.Orders
        Dim order = objectSpace.GetObject(rawOrder) 'Document in current ObjectSpace.
        order.Freight = order.Freight + (order.Freight * rate)
        Dim oldFreight = order.Freight
        Dim msg = String.Format("Order # {0}. Previous freight cost {1}, new {2}", order.Number, oldFreight, order.Freight)
    End Using
  End Sub
End Class

As shown in the example, when using OperationServiceBase as a base class, it is often sufficient to override the Execute() abstract method that contains the logic of the Business Operation.

Also it is possible to implement a rollback of the BO if necessary. To do so, implement the IOperationServiceReversible interface that declares the Rollback() method.

To specify that the Implementation belongs to a certain BO, use BusinessOperationAttribute. To learn about other Implementation attributes, refer to the Business Operation Implementation Attributes topic.