# create method

1. @protected

Future<Object> create(

1. String podName,
2. RootPodDefinition root,
3. List<ArgumentValue>? args

)

Creates a pod instance with the given name and definition.

This method handles the complete pod creation lifecycle including instantiation, population, and initialization.

@param podName The name of the pod to create @param root The pod definition @param args Optional constructor arguments @return The created pod instance

## Implementation

    @protected
    Future<Object> create(String podName, RootPodDefinition root, List<ArgumentValue>? args) async {
      // Instantiate the pod
      PodHolder? podHolder;

      if (root.scope.isSingleton) {
        final obj = podProviderInstanceCache.remove(podName);
        final cls = obj?.getType();

        if (obj != null && cls != null) {
          podHolder = (obj.getValue(), cls);
        }
      }

      podHolder ??= await createInstance(podName, root, args);

      final earlySingletonExposure = root.scope.isSingleton && getAllowCircularReferences() && isCurrentlyCreatingSingleton(podName);

      Object pod = podHolder.$1;
      Class podClass = podHolder.$2;

      if (earlySingletonExposure) {
        if (logger.getIsTraceEnabled()) {
          logger.trace('Eagerly caching pod $podName to allow potential circular references resolution');
        }

        final create = () async {
          return await getEarlyPodReference(
            podName,
            root,
            ObjectHolder(pod, packageName: podClass.getPackage()?.getName(), qualifiedName: podClass.getQualifiedName())
          );
        };

        addSingleton(podName, factory: SimpleObjectFactory(([args]) async => create()));
      }

      Object exposed = pod;

      try {
        // Populate the pod instance
        await populate(podName, root, podHolder);

        // Initialize the pod
        exposed = await initializeExistingPod(exposed, podHolder.$2, podName);
      } catch (e) {
        if (e is PodCreationException && e.getPodName().equals(podName)) {
          rethrow;
        }

        final message = e is Throwable ? e.getMessage() : e.toString();
        final cause = e is Throwable ? e : RuntimeException(e.toString());

        throw PodCreationException.withResource(root.description, podName, message, cause: cause);
      }

      if (earlySingletonExposure) {
        final earlyReference = await getSingleton(podName, allowEarlyReference: false);
        if (earlyReference != null) {
          if (exposed == pod) {
            exposed = earlyReference;
          } else if (!_allowRawInjectionDespiteWrapping && hasDependentPod(podName)) {
            final dependents = getDependentPods(podName);
            final actualDependents = Set.from(dependents);

            for (String dependent in dependents) {
              if (!removeSingletonIfCreated(dependent)) {
    							actualDependents.remove(dependent);
    						}
            }

            if (actualDependents.isNotEmpty) {
              throw PodCurrentlyInCreationException(
                name: podName,
                msg: "Pod $podName has been injected into other pods ${actualDependents.join(', ')} "
                "in its raw (uninitialized) form as part of a circular reference. This means that "
                "mentioned pods do not use the final (fully initialized) form of $podName. "
                "This is often the result of over-zealous circular reference prevention. "
                "Consider using 'getPodsForType' with the 'allowEagerInit' flag turned off."
              );
            }
          }
        }
      }

      // Register pod as disposable (if it is a disposable)
      if (exposed is DisposablePod) {
        try {
          registerDisposableHandler(podName, exposed, root);
        } on PodDefinitionValidationException catch (e) {
          throw PodCreationException.withResource(root.description, podName, "Invalid disposable pod", cause: e);
        }
      }

      return exposed;
    }