Table of Contents

Custom validation

Implement your own validator to perform validations before create update and delete operations.

Deployment. A validator is a class inside a .NET 8 customisation DLL. The DLL is loaded by the FrontEnd Server (BFF) — it must land in /app/Custom/ on the BFF container (the same overlay path used for custom components). See the Hands-On Tutorial — Step 13 for a complete docker-compose-mounted example, and Component Authoring — Backend overlay for the broader overlay model.

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 validator

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

Component level

Validators targeting components support both data-scoped and component-scoped validation methods.

  • Data-Scoped Validations Focus on a single entity.
    • Examples:
      • Validating fields of a Form Component on create/update.
      • Validating fields of a new or edited row in a Related List.
  • Component-Scoped Validations: Evaluate all changes made to the entities of the component simultaneously to determine validity.
    • Example: Assessing all new, modified, or removed rows from a Related List Component to determine if the component's state is valid.

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

Page level (Coming soon)

Page-scoped validations are intended for:

  • Validations that require evaluating the persistence data of all components on the page simultaneously to determine validity.

Page Validator is planned for future development and is not yet available.

Step 3: Configure in database

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

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

  • Page: (Coming soon)
  • Component: MIB3UX_PAGE_COMPONENT_CONFIGURATIONS

The required configuration keys are described below:

  • VALIDATION_ASSEMBLY_NAME: Specifies the assembly where the validator implementation is located.
  • VALIDATION_CLASS_NAME: Specifies the class in the specified assembly that is the concrete validator to be used, including the namespace.

Example

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

CONFIGURATION_KEY CONFIGURATION_VALUE
VALIDATION_ASSEMBLY_NAME MibCustomComponent.Sample
VALIDATION_CLASS_NAME MibCustomComponent.Sample.FormValidation.MyConcreteFormComponentValidator