getIfUnique method
Retrieves the object only if exactly one instance exists, or returns null.
- NoUniquePodDefinitionException if more than one matching object exists.
Implementation
Future<ObjectHolder<T>?> getIfUnique([Supplier<ObjectHolder<T>>? supplier]) async {
ObjectHolder<T>? result;
try {
result = await get();
} on NoUniquePodDefinitionException catch(_) {
rethrow;
} on NoSuchPodDefinitionException catch(_) {
result = null;
}
return result ?? supplier?.call();
}