BeanNameAware class abstract interface

A bean that is told the name it is registered under.

Useful when several beans share one class and each must know which one it is, for example to read its own settings or to label its logs. Most beans do not care about their name.

// Two workers of the same class, registered as 'importer' and
// 'exporter'; each reports under its own name.
@Component()
class Worker implements BeanNameAware {
  late final String id;

  @override
  void setBeanName(String name) => id = name;
}

Spring (Java):

@Component
class Worker implements BeanNameAware {
  String id;
  @Override public void setBeanName(String name) { id = name; }
}
Implemented types

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

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setBeanName(String name) → void
Receives the bean's name (never one of its aliases). Called once, after injection and before BeanFactoryAware.setBeanFactory.
toString() → String
A string representation of this object.
inherited

Operators

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