get<T> method

  1. @override
Future<T> get<T>(
  1. Class<T> type, [
  2. List<ArgumentValue>? args
])

Retrieves a pod instance by its type with optional arguments.

This method looks up a pod by its class type and returns an instance. It's useful when you want to retrieve pods by type rather than by name.

Usage Example:

final service = await factory.get<MyService>();

// With constructor arguments
final controller = await factory.get<MyController>([
  ArgumentValue('maxRetries', 3),
  ArgumentValue('enableLogging', true),
]);

@param type The class type of the pod to retrieve @param args Optional list of argument values for pod construction @return A Future that completes with the pod instance of type T @throws PodNotFoundException if no pod of the specified type is registered

Implementation

@override
Future<T> get<T>(Class<T> type, [List<ArgumentValue>? args]) async {
  final f = getPodFactory();

  // Prefer local beans (without forcing eager init of parent beans)
  if (await _hasLocalPodsOfType(type)) {
    return await f.get(type, args);
  }

  // Fallback to parent
  if (_parent != null) {
    return await _parent!.get(type, args);
  }

  throw NoSuchPodDefinitionException.byTypeWithMessage(type, 'No pod of type ${type} found in context or ancestors');
}