Conditional class
The Conditional
annotation in Jetleaf allows developers to specify
conditions that must be satisfied for a class or method to be processed
by the framework.
This annotation is typically used on configuration classes, pods, or
methods that should only be included when certain runtime conditions are met.
Conditions are implemented as classes that implement the Condition
interface.
Key Features:
- Supports multiple conditions; all must match for the annotated type to be processed.
- Can be applied to both classes and methods.
Usage Example:
import 'package:jetleaf/jetleaf.dart';
// A condition that only matches when the application is running in production
class OnProductionEnvironmentCondition implements Condition {
@override
bool matches(ConditionalContext context, ClassType<Object> classType) {
return context.environment.activeProfiles.contains('production');
}
}
// Apply conditional configuration
@Conditional([ClassType<OnProductionEnvironmentCondition>()])
class ProductionDataSourceConfig {
// Beans/pods defined here will only be registered in production
}
In this example, ProductionDataSourceConfig
will only be processed by Jetleaf
if OnProductionEnvironmentCondition
evaluates to true
. This allows
developers to define environment-specific configuration easily.
- Annotations
-
- @Target.new({TargetKind.classType, TargetKind.method})
Constructors
-
Conditional(List<
ClassType< conditions)Condition> > -
The
Conditional
annotation in Jetleaf allows developers to specify conditions that must be satisfied for a class or method to be processed by the framework.const
Properties
- annotationType → Type
-
Returns the annotation _type of this annotation.
no setter
-
conditions
→ List<
ClassType< Condition> > -
Condition classes that must match for the annotated type to be processed.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
equalizedProperties(
) → List< Object?> -
Mixin-style contract for value-based equality,
hashCode
, andtoString
. -
equals(
Object other) → bool -
Checks whether the given object is logically equivalent to this annotation.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String - Returns a string representation of this annotation.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited