Dynamic Expressions

Overview

Dynamic expressions provide a mechanism to define variables within your Business Rules Framework models that can be configured at runtime through external sources such as HOCON files or programmatic registration.

Key Concepts

Dynamic expressions consist of three main components:

  1. Dynamic Variables - Type-safe variable definitions generated from MPS value libraries, with default values that can be overridden at runtime

  2. DynamicExpressionRegistry - A central registry that stores configured values and provides them to generated code during execution

  3. Configuration Sources - Pluggable providers (like HOCON files) that load values into the registry at application startup

How It Works

The workflow is:

  1. Define dynamic variables in an MPS value library with default values

  2. MPS generates a DynamicVariableLibrary class containing the variable definitions

  3. At application startup, configuration sources load values into the DynamicExpressionRegistry

  4. When generated code executes, it resolves variable values from the registry (or uses defaults)

Dynamic Variables vs Value Libraries

Dynamic variables are defined within value libraries but serve a different purpose:

Value Library Values Dynamic Variables

Static values compiled into generated code

Runtime-configurable values with defaults

Cannot be changed without rebuilding

Can be overridden via external configuration

Ideal for constants and static data

Ideal for environment-specific settings, thresholds, feature flags

Scoping

The DynamicExpressionRegistry supports two levels of scoping:

  • Global scope - Values available to all executions

  • Entity scope - Values specific to a processing context (e.g., per-transaction overrides)

Entity-scoped values take precedence over global values, allowing fine-grained control when needed.

Use Cases

Dynamic expressions are well-suited for:

  • Environment-specific thresholds (e.g., different limits for dev/prod)

  • Feature flags that can be toggled without redeployment

  • Business parameters that change based on operational requirements

  • Per-entity configuration in multi-tenant scenarios

Getting Started

To use dynamic expressions in your application:

  1. Define dynamic variables in your MPS value library

  2. Add the ipf-studio-configuration-hocon-spring-starter dependency

  3. Create a HOCON configuration file with your values

  4. The Spring Boot auto-configuration handles registration automatically