ConditionalContext class

Represents the conditional evaluation context in JetLeaf applications.

A ConditionalContext provides all necessary runtime information to determine whether a pod, component, or configuration should be activated based on environment variables, runtime conditions, active profiles, or the presence/absence of other pods.

This context is passed to condition evaluators such as OnPropertyCondition, OnProfileCondition, OnPodCondition, or custom conditional evaluators to decide if annotated elements should be processed. It serves as the central point of access for environment, pod lifecycle, and runtime information required for conditional logic.

Purpose

  • Enables declarative conditional activation of pods and components.
  • Provides a unified interface for querying runtime and environment state.
  • Supports modular and environment-specific configurations in JetLeaf applications.
  • Reduces boilerplate by centralizing access to Environment, PodFactory, and RuntimeProvider.

Behavior

  • Maintains a list of unregistered PodDefinition instances that have been discovered but not yet registered.
  • Ensures thread-safe updates to pod definitions using addDefinition.
  • Provides immutable access to currently unregistered pods via getUnregisteredDefinitions.
  • Works seamlessly with JetLeaf's conditional evaluation framework, allowing multiple conditions to evaluate consistently using the same context.

Example

final context = ConditionalContext(environment, podFactory, runtimeProvider);

// Query active profiles
if (context.environment.activeProfiles.contains('production')) {
  print('Running in production mode.');
}

// Add a new pod definition safely
context.addDefinition(PodDefinition('cacheManager'));

// Retrieve unregistered definitions
final pendingPods = context.getUnregisteredDefinitions();
for (var pod in pendingPods) {
  print('Pending pod: ${pod.name}');
}
  • Environment: Provides access to application properties, system settings, and active profiles.
  • ConfigurableListablePodFactory: Manages lifecycle of pods and allows retrieval or configuration of pod instances.
  • RuntimeProvider: Provides runtime-specific information required for conditional evaluation.
  • PodDefinition: Represents the metadata and configuration of a pod before registration.
Implementers

Constructors

ConditionalContext(Environment environment, ConfigurableListablePodFactory podFactory)
Represents the conditional evaluation context in JetLeaf applications.

Properties

environment → Environment
Access application properties, system settings, and active profiles. Often used in condition evaluations to determine whether a pod should be activated.
final
hashCode int
The hash code for this object.
no setterinherited
podFactory → ConfigurableListablePodFactory
Manages the lifecycle of pods in the current context. Developers can programmatically retrieve or configure pods.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addDefinition(PodDefinition definition) → void
Adds a PodDefinition to the list of unregistered definitions. Thread-safe and ensures uniqueness by removing existing instances before re-adding.
getUnregisteredDefinitions() List<PodDefinition>
Returns an immutable snapshot of unregistered PodDefinition instances. External modifications do not affect the internal state.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited