getSingleton method
Retrieve the pod registered under name
.
This method returns the pod associated with the given name.
The exact behavior and returned type depend on the registry
implementation and the generic type T
.
name
: The name of the pod to retrieve
Returns the pod object of type T
associated with the name
Throws:
IllegalArgumentException
if name is null or emptyPodNotFoundException
if no pod exists with the given name
Example:
// Get a singleton instance
final instance = singletonRegistry.getSingleton('userService');
instance.processRequest();
Implementation
@override
Future<Object?> getSingleton(String name, {bool allowEarlyReference = true, ObjectFactory<Object>? factory}) async {
// prefer local singleton; if not found, delegate to parent (no exceptions swallowed)
final f = getPodFactory();
if (f.containsSingleton(name)) return await f.getSingleton(name, allowEarlyReference: allowEarlyReference, factory: factory);
if (_parent != null) return await _parent!.getPodFactory().getSingleton(name, allowEarlyReference: allowEarlyReference, factory: factory);
return null;
}