Table of Contents

Implementing a Custom Business Rule

Implement your own business rule to perform validations and/or modifications before create, update, and delete operations.

Step 1: Add required NuGet Package

In your .csproj file, add a reference to the NuGet package MediaiBox.Cms.FrontEnd.Model.

Step 2: Implement a Business Rule

To implement a business rule, first choose the appropriate base business rule class. This section will help you make that decision. Once you have selected the base class, click on the corresponding documentation link for instructions on writing your business logic.

Component Level

Business rules targeting components support both data-scoped and component-scoped logic execution.

  • Data-Scoped Business Rules: Focus on a single entity.

    • Examples:

      • Validating or modifying fields of a Form Component on create/update.
      • Validating or modifying fields of a new or edited row in a Related List.
  • Component-Scoped Business Rules: Evaluate all changes made to the entities of the component simultaneously to determine if business conditions are met.

    • Example: Assessing all new, modified, or removed rows from a Related List Component to enforce consistency or apply mass changes.

For more information on writing custom business rules for the target component, refer to:

Page Level (Coming soon)

Page-scoped business rules are intended for:

  • Logic that requires evaluating the persistence data of all components on the page simultaneously to determine consistency or apply cross-component rules.

Page-level Business Rule support is planned for future development and is not yet available.

Step 3: Configure in Database

After implementing the business rule, the next step is to create configurations in the database. This allows MIB to load the business rule via reflection and call it at the appropriate time.

The configuration involves specifying the name of the assembly and the business rule class to be used. The table where the configuration needs to be added depends on whether your business rule targets a page or a component:

  • Page: (Coming soon)
  • Component: MIB3UX_PAGE_COMPONENT_CONFIGURATIONS

The required configuration keys are described below:

  • BUSINESSRULE_ASSEMBLY_NAME: Specifies the assembly where the business rule implementation is located.
  • BUSINESSRULE_CLASS_NAME: Specifies the class in the specified assembly that is the concrete business rule to be used, including the namespace.

Example

For example, configuring a custom business rule for a Form Component should be done in table MIB3UX_PAGE_COMPONENT_CONFIGURATIONS:

CONFIGURATION_KEY CONFIGURATION_VALUE
BUSINESSRULE_ASSEMBLY_NAME MibCustomComponent.Sample
BUSINESSRULE_CLASS_NAME MibCustomComponent.Sample.FormValidation.MyConcreteFormComponentBusinessRule