SingletonPodRegistry class abstract

Interface for registries that hold singleton pod instances.

This interface defines the contract for managing singleton pods within the JetLeaf framework. Singleton pods are objects that are instantiated once and shared throughout the application context.

Key responsibilities:

  • Registering singleton instances by name
  • Retrieving singleton instances by name
  • Checking for singleton existence
  • Providing singleton metadata and statistics
  • Thread-safe singleton management

Implementations of this interface are responsible for the complete lifecycle management of singleton pods, including:

  • Early singleton instantiation during context startup
  • Singleton caching and reuse
  • Dependency injection for singleton pods
  • Proper cleanup during context shutdown

Example usage:

class MySingletonRegistry implements SingletonPodRegistry {
  final Map<String, Object> _singletons = {};
  final Object _mutex = Object();

  @override
  void register(String name, String qualifiedName, Object singletonObject) {
    _singletons[name] = singletonObject;
  }

  @override
  Object? get(String name) => _singletons[name];

  // ... other interface implementations
}

final registry = MySingletonRegistry();
registry.register('userService', 'package:example/example.dart.UserService', UserService());
final service = registry.get('userService');
Implementers

Constructors

SingletonPodRegistry()

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

addSingletonCallback(String name, Class type, Consumer<Object> callback) → void
Add a callback to be executed when the singleton associated with name is initialized.
clearSingletonCache() → void
Clears all cached singleton pods.
containsSingleton(String name) bool
Returns true if this registry contains a pod with the given name.
getSingleton(String name, {bool allowEarlyReference = true, ObjectFactory<Object>? factory}) Future<Object?>
Retrieve the pod registered under name.
getSingletonCount() int
Returns the total number of pods registered.
getSingletonNames() List<String>
Returns a list of all pod names currently registered.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerSingleton(String name, Class type, {ObjectHolder<Object>? object, ObjectFactory<Object>? factory}) Future<void>
Register a new pod under the given name.
removeSingleton(String name) → void
Remove the pod associated with name.
toString() String
A string representation of this object.
inherited

Operators

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