Lookup class

Marks a method that returns a bean of the container on every call.

A singleton receives its dependencies once. When it needs a fresh prototype bean each time (a command, a unit of work), it declares a @Lookup method: every call returns the bean named value, else the bean of the method's return type.

The bean is created as a generated subclass that overrides the method. The method may be abstract (then the class may be abstract too: an abstract @Component class with @Lookup methods is a bean, unlike other abstract classes) or concrete (its body never runs). A nullable return type gives null when no bean of the type exists.

Dart limits, checked at build time: the method must be public, take no parameters (Spring passes them as constructor arguments to getBean) and not be generic; the class must be extendable from the generated library (not final, sealed or interface), have a public generative constructor and not be a full-mode @Configuration class.

@Component()
@Scope(ScopeType.prototype)
class Command {}

@Component()
abstract class CommandManager {
  @Lookup()
  Command createCommand(); // a new Command per call

  @Lookup('auditLog')
  AuditLog auditLog(); // the bean named `auditLog`

  void process() => createCommand().run();
}

Spring (Java):

@Component
public abstract class CommandManager {
  @Lookup
  protected abstract Command createCommand();

  @Lookup("auditLog")
  protected abstract AuditLog auditLog();
}

Constructors

Lookup([String? value])
Marks the lookup method; value names the bean to return.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
value → String?
The name (or alias) of the bean to return; null looks it up by the method's return type.
final

Methods

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