π« Interface for components that need to know their assigned pod name.
The PodNameAware interface allows framework-managed components to discover their registration name within the dependency injection container.
Common Use Cases:
- Logging and Diagnostics: Include pod name in log messages
- Dynamic Configuration: Load configuration based on pod identity
- Conditional Behavior: Implement logic that varies by pod name
- Metadata Association: Associate additional metadata with the pod
Framework Integration:
- Called automatically after pod instantiation
- Invoked after PodFactoryAware but before
@PostConstruct
methods - The provided name matches the registration name in the PodFactory
Example Usage:
@Component
class NamedService implements PodNameAware {
late String _podName;
final List<String> _operations = [];
@override
void setPodName(String name) {
_podName = name;
}
void performOperation(String operation) {
_operations.add(operation);
print('Service "$_podName" performed: $operation');
}
String getServiceInfo() {
return 'Service "$_podName" has performed ${_operations.length} operations';
}
}
Best Practices:
- Use pod names for identification, not for business logic when possible
- Consider using
@Qualifier
annotations for disambiguation instead - Pod names may change between different environments or configurations
See also:
- PodFactoryAware for container access
- ApplicationContextAware for broader context awareness
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
-
setPodName(
String name) β void - Sets the name under which this component is registered in the PodFactory.
-
toString(
) β String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) β bool -
The equality operator.
inherited