{"record":{"id":"2ed71d69ab8786cd","repo":"phalcon/cphalcon","slug":"cannot-resolve-a-fresh-name-it-is-not-bound-i","errorCode":null,"errorMessage":"Cannot resolve a fresh '{name}': it is not bound in the container","messagePattern":"Cannot resolve a fresh '(.+?)': it is not bound in the container","errorType":"exception","errorClass":"Phalcon\\Container\\Exceptions\\Exception","httpStatus":null,"severity":"error","filePath":"phalcon/Auth/Internal/ContainerResolver.zep","lineNumber":117,"sourceCode":"    }\n\n    /**\n     * Resolves a fresh instance: new() on the Container (bypasses the\n     * instance cache); get() on the legacy Di (fresh for unregistered or\n     * non-shared services). On Di, an unregistered but existing class is\n     * still built via the class builder.\n     *\n     * @throws ContainerException\n     */\n    public static function resolveFresh(var container, string name) -> object\n    {\n        var e;\n\n        self::ensureContainer(container);\n\n        if (container instanceof Collection) {\n            if (true !== container->has(name)) {\n                throw new ContainerException(\n                    \"Cannot resolve a fresh '\" . name\n                    . \"': it is not bound in the container\"\n                );\n            }\n\n            return container->{\"new\"}(name);\n        }\n\n        if (true !== container->has(name) && !class_exists(name)) {\n            throw new ContainerException(\n                \"Cannot resolve a fresh '\" . name\n                . \"': it is not registered in the Di and is not an existing class\"\n            );\n        }\n\n        try {\n            return container->get(name);\n        } catch DiException, e {","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Auth/Internal/ContainerResolver.zep#L99-L135","documentation":"ContainerResolver::resolveFresh() resolves a NEW (non-shared) instance of a service. When the container is the new Phalcon Container (a Service Collection), there is no autowiring fallback: the service must already be bound. If the collection has no binding for the requested name, this ContainerException is thrown. Contrast with the legacy Di branch (error 46), which additionally allows unregistered-but-existing classes.","triggerScenarios":"Calling resolveFresh($collection, 'guard-name') (directly, or via Auth internals that build fresh guard/adapter instances) against a Phalcon Container collection in which that name was never registered.","commonSituations":"Migrating from legacy Di to the new Container and assuming the class-builder fallback still applies; constructing guards lazily while forgetting to define them in the Container; name typos between the definition and the lookup.","solutions":["Register the service in the Container collection under the exact name being resolved before requesting a fresh instance","If you relied on legacy Di's build-any-existing-class behavior, keep using a DiInterface container for that resolution","Double-check for name mismatches/typos between the binding key and the requested name"],"exampleFix":"// before\n$container = new \\Phalcon\\Container\\Container();\n// nothing bound under 'streamAdapter'\n\n// after\n$container->set('streamAdapter', \\Phalcon\\Auth\\Adapter\\Stream::class);","handlingStrategy":"validation","validationCode":"if ($container instanceof \\Phalcon\\Contracts\\Container\\Service\\Collection && !$container->has($name)) {\n    throw new RuntimeException(\"'{$name}' must be bound in the Container before fresh resolution\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    $instance = $resolverFreshPath; // whatever triggers resolveFresh\n} catch (\\Phalcon\\Container\\Exceptions\\Exception $e) {\n    // bind the service and retry; no autowiring fallback exists on Collection\n}","preventionTips":["Bind every service name you plan to resolve into the Container collection up front","Remember the fresh path only auto-builds classes on the legacy Di, not on Collection","Centralize binding names in constants shared by producer and consumer code"],"tags":["auth","dependency-injection","container","service-not-found"],"backgroundTag":"missing-di-service","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}