# instantiateUsingConstructor method

1. @protected

Future<Object> instantiateUsingConstructor(

1. String podName,
2. RootPodDefinition root,
3. List<Constructor>? chosenConstructors,
4. List<ArgumentValue>? explicitArgs,

)

Instantiates a pod using constructor injection.

This method selects the appropriate constructor and resolves all constructor arguments through dependency injection.

@param podName The name of the pod @param root The pod definition @param chosenConstructors Optional specific constructors to use @param explicitArgs Optional explicit arguments @return The autowired instance

## Implementation

    @protected
    Future<Object> instantiateUsingConstructor(String podName, RootPodDefinition root, List<Constructor>? chosenConstructors, List<ArgumentValue>? explicitArgs) async {
      final result = await _executableStrategy.determineConstructor(root, podName, chosenConstructors, explicitArgs);
      final constructor = result.executable as Constructor;

      try {
        if (logger.getIsTraceEnabled()) {
          logger.trace(
            "Instantiating pod '$podName' using constructor '${constructor.getName()}' "
            "with args: named=${result.namedArgs}, positional=${result.positionalArgs}",
          );
        }

        return constructor.newInstance(result.namedArgs, result.positionalArgs);
      } on PodException catch (e, st) {
        if(logger.getIsTraceEnabled()) {
          logger.trace("Pod instantiation failed for '$podName' via constructor '${constructor.getName()}': $e", error: e, stacktrace: st);
        }

        rethrow;
      } catch (e, st) {
        if(logger.getIsTraceEnabled()) {
          logger.trace("Unexpected error while instantiating pod '$podName' via constructor '${constructor.getName()}': $e\n$st", error: e, stacktrace: st);
        }

        rethrow;
      }
    }