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:
-
Dynamic Variables - Type-safe variable definitions generated from MPS value libraries, with default values that can be overridden at runtime
-
DynamicExpressionRegistry - A central registry that stores configured values and provides them to generated code during execution
-
Configuration Sources - Pluggable providers (like HOCON files) that load values into the registry at application startup
How It Works
The workflow is:
-
Define dynamic variables in an MPS value library with default values
-
MPS generates a
DynamicVariableLibraryclass containing the variable definitions -
At application startup, configuration sources load values into the
DynamicExpressionRegistry -
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:
-
Define dynamic variables in your MPS value library
-
Add the
ipf-studio-configuration-hocon-spring-starterdependency -
Create a HOCON configuration file with your values
-
The Spring Boot auto-configuration handles registration automatically