ExecutableInstantiator class abstract interface

Provides a high-level, reflection-based utility to dynamically instantiate classes and invoke methods on objects at runtime, while automatically resolving arguments and selecting the most appropriate executable.

The ExecutableInstantiator is designed for frameworks or libraries that require dynamic execution of constructors or methods without static knowledge of their signatures. It leverages:

  • Executable selectors to choose the best matching constructor or method
  • Argument resolvers to automatically provide values for positional and named parameters

Core Responsibilities

  1. Dynamically instantiate classes discovered at runtime
  2. Dynamically invoke instance methods on objects
  3. Automatically select the best executable using configurable rules
  4. Auto-resolve constructor and method parameters based on type bindings or predicates
  5. Provide fluent API for chaining selectors and argument resolvers

Use Cases

  • Dynamic plugin or module instantiation
  • Runtime method invocation with dependency injection support
  • Reflection-based framework utilities
  • Dynamic wiring of services or components discovered at runtime

Example

final instantiator = ExecutableInstantiator.of(MyClass)
  .withSelector(ExecutableSelector().and(Class<ApplicationContext>()))
  .withArgumentResolver(ExecutableArgumentResolver().and(Class<ApplicationContext>(), context);

// Create a new instance
final instance = instantiator.newInstance<MyClass>();

// Invoke a method dynamically
final result = instantiator.invoke<String>(instance, "doWork");

Constructors

ExecutableInstantiator.of(Class cls)
Creates a new ExecutableInstantiator for the specified class cls.
factory

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

invoke<Executed>(Object? instance, String methodName) → Executed?
Dynamically invokes a method with the specified methodName on the given instance.
newInstance<Executed>({bool checkNoArgFirst = true, bool tryDefault = false}) → Executed?
Dynamically creates a new instance of the underlying class cls.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
withArgumentResolver(ExecutableArgumentResolver resolver) ExecutableInstantiator
Assigns a custom ExecutableArgumentResolver used to resolve the arguments of constructors or methods dynamically.
withSelector(ExecutableSelector selector) ExecutableInstantiator
Assigns a custom ExecutableSelector to determine which executable (constructor or method) will be used when creating instances or invoking methods.

Operators

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