Executable Strategy
Defines the contract for strategies that determine how a pod (instance) should be created by selecting an appropriate constructor or factory method.
This abstraction allows the framework to support multiple instantiation policies (e.g., annotation-driven, autowiring, explicit argument matching).
Purpose
- Encapsulates the logic of deciding which executable (constructor or factory method) to invoke when instantiating a pod.
- Provides flexibility so different strategies can be plugged in depending on framework configuration.
- Used internally by the DefaultListablePodFactory (or equivalents) during pod creation.
Common Strategies
- Default constructor strategy: Always selects the no-arg constructor.
- Annotated strategy: Selects constructors/methods marked with a
specific annotation (e.g.,
@Inject). - Autowiring strategy: Resolves arguments automatically from the dependency graph.
- Explicit arguments strategy: Prefers explicitly provided arguments when available.
Example Usage
final strategy = MyAnnotationBasedExecutableStrategy();
final holder = await strategy.determineConstructor(
rootDef,
"myService",
rootDef.constructors,
[ArgumentValue.positional("db_connection")]
);
print(holder.executable); // chosen constructor
print(holder.arguments); // resolved arguments
Notes for Implementors
- Must return an ExecutableHolder with both the chosen executable and its resolved arguments.
- Should fail fast with a clear error if no suitable constructor/factory can be determined.
- May use metadata (annotations, profiles, qualifiers) from RootPodDefinition to guide selection.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
determineConstructor(
RootPodDefinition rpd, String podName, List< Constructor> ? constructors, List<ArgumentValue> ? explicitArgs) → Future<ExecutableHolder> - Determine which constructor should be used for pod creation.
-
determineFactoryMethod(
RootPodDefinition rpd, String podName, List< ArgumentValue> ? explicitArgs) → Future<ExecutableHolder> - Determine which factory method should be used for pod creation.
-
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