{"record":{"id":"e399c81edd105838","repo":"emberjs/ember.js","slug":"cannot-call-factoryfor-fullname-after-the","errorCode":null,"errorMessage":"Cannot call `.factoryFor('${fullName}')` after the owner has been destroyed","messagePattern":"Cannot call `\\.factoryFor\\('(.+?)'\\)` after the owner has been destroyed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@ember/-internals/container/lib/container.ts","lineNumber":223,"sourceCode":"  ownerInjection() {\n    let injection = {};\n    setOwner(injection, this.owner!);\n    return injection;\n  }\n\n  /**\n   Given a fullName, return the corresponding factory. The consumer of the factory\n   is responsible for the destruction of any factory instances, as there is no\n   way for the container to ensure instances are destroyed when it itself is\n   destroyed.\n    @public\n   @method factoryFor\n   @param {String} fullName\n   @return {any}\n   */\n  factoryFor(fullName: FullName): InternalFactoryManager<object> | undefined {\n    if (this.isDestroyed) {\n      throw new Error(\n        `Cannot call \\`.factoryFor('${fullName}')\\` after the owner has been destroyed`\n      );\n    }\n    let normalizedName = this.registry.normalize(fullName);\n\n    assert('fullName must be a proper full name', this.registry.isValidFullName(normalizedName));\n\n    return factoryFor(this, normalizedName, fullName);\n  }\n}\n\nif (DEBUG) {\n  Container._leakTracking = leakTracking!;\n}\n\n/*\n * Wrap a factory manager in a proxy which will not permit properties to be\n * set on the manager.","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/emberjs/ember.js/blob/26f97246a8bf2e28edf26ac3093da2e86c04ffc5/packages/@ember/-internals/container/lib/container.ts#L205-L241","documentation":"Container#factoryFor refuses to return a factory manager after the owner has been destroyed. Like lookup, factory resolution is invalid post-teardown; Ember throws to surface lifecycle bugs rather than hand back unusable factories.","triggerScenarios":"Calling owner.factoryFor('service:foo') after owner.destroy() — commonly in deferred async code, leftover observers, or during test teardown.","commonSituations":"Test teardown racing with pending promises; code caching an owner and using it after app destroy; engine teardown while child components still resolve factories.","solutions":["Cancel/complete pending async work before the owner is destroyed","Guard calls with isDestroying/isDestroyed checks on the owner","Move factory resolution earlier in the lifecycle (before teardown begins)","In tests, ensure settled() before teardown"],"exampleFix":"// before\nlet Factory = owner.factoryFor('model:user').class;\n// after\nif (!owner.isDestroyed) {\n  let Factory = owner.factoryFor('model:user').class;\n}","handlingStrategy":"validation","validationCode":"if (owner.isDestroyed) return; let mgr = owner.factoryFor('service:foo');","typeGuard":"function canFactoryFor(owner) { return Boolean(owner) && !owner.isDestroyed && !owner.isDestroying; }","tryCatchPattern":"try { return owner.factoryFor(fullName); } catch (e) { if (String(e.message).includes('factoryFor') && e.message.includes('destroyed')) return undefined; throw e; }","preventionTips":["Resolve factories early in the component/service lifecycle","Cancel run.later/promises in willDestroy","Guard post-teardown async continuations","Use settled() in tests"],"tags":["ember","lifecycle","container","factory-for"],"backgroundTag":"lookup-after-destroy","analyzedSha":"26f97246a8bf2e28edf26ac3093da2e86c04ffc5","analyzedAt":"2026-09-01T05:01:28.182Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}