public static function buildContainer(): Container
    {
        if (self::$container !== null) {
            return self::$container;
        }

        $factory = new ContainerBuilder();
        $factory->useAnnotations(true);

        if ((new ContextHelper())->isProduction()) {
            $factory->enableDefinitionCache();

            if (!is_dir(MELIOR_BASE.'/Data/Persistent/Container/Proxies')) {
                mkdir(MELIOR_BASE.'/Data/Persistent/Container/Proxies', 0755, true);
            }

            $factory->enableCompilation(MELIOR_BASE.'/Data/Persistent/Container');
            $factory->writeProxiesToFile(true, MELIOR_BASE.'/Data/Persistent/Container/Proxies');
        }

        $packages = (new PackageService(new PathHelper(), new ComposerParser()))->getApplicationPackages();

        foreach ($packages as $name => $data) {
            $extra = $data->getExtra();

            if (!array_key_exists('melior', $extra)) {
                continue;
            }

            $meliorData = $extra['melior'];

            if (!array_key_exists('containerDefinitions', $meliorData)) {
                continue;
            }

            $definitions = $meliorData['containerDefinitions'];

            if (is_string($definitions)) {
                $definitions = [$definitions];
            } elseif (!is_array($definitions)) {
                continue;
            }

            foreach ($definitions as $definitionFile) {
                $filepath = realpath("$name/$definitionFile");

                if (!is_file($filepath) || !\is_readable($filepath)) {
                    continue;
                }

                $factory->addDefinitions($filepath);
            }
        }

        $container = $factory->build();

        self::$container = $container;

        return $container;
    }