Title: DI feature: lifecycle hooks for services, especially OnDestroy · Issue #13618 · angular/angular · GitHub
Open Graph Title: DI feature: lifecycle hooks for services, especially OnDestroy · Issue #13618 · angular/angular
X Title: DI feature: lifecycle hooks for services, especially OnDestroy · Issue #13618 · angular/angular
Description: I'm submitting a ... (check one with "x") [ ] bug report [x] feature request [ ] support request Current behavior When destroying an injector, Angular has no way AFAIK to inform the service instances in the injector that they are doomed....
Open Graph Description: I'm submitting a ... (check one with "x") [ ] bug report [x] feature request [ ] support request Current behavior When destroying an injector, Angular has no way AFAIK to inform the service instanc...
X Description: I'm submitting a ... (check one with "x") [ ] bug report [x] feature request [ ] support request Current behavior When destroying an injector, Angular has no way AFAIK to inform the s...
Opengraph URL: https://github.com/angular/angular/issues/13618
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"DI feature: lifecycle hooks for services, especially OnDestroy","articleBody":"**I'm submitting a ...** (check one with \"x\")\r\n```\r\n[ ] bug report \r\n[x] feature request\r\n[ ] support request \r\n```\r\n\r\n**Current behavior**\r\n\r\nWhen destroying an injector, Angular has no way AFAIK to inform the service instances in the injector that they are doomed.\r\n\r\nIf a service is holding valuable resources (e.g., a message bus holding subscriptions) it doesn't know to let go.\r\n\r\n**Expected behavior**\r\n\r\nIf the service has an `ngOnDestroy`, Angular should call it as it destroys/releases its hold on an injector (e.g., when destroying a component).\r\n\r\nIs this safe? Only if the service is created by the injector ... which isn't _always_ the case ( almost anything except `useClass`).\r\n\r\nOTOH, if the developer adds an `ngOnDestroy` method, she should expect it to be called and not put her service in compromising position.\r\n\r\nOn balance, I think its a useful feature, with no obvious substitution, and one *consistent with disposable patterns in other languages*.\r\n\r\np.s.: The only other lc-hook that makes sense is `ngOnInit` and the developer can easily compensate for its lack. I can't think of workaround for the lack of `ngOnDestroy`.\r\n\r\n\u003c!-- Operating system, IDE, package manager, HTTP server, ... -->\r\nAll\r\n\r\n* **Angular version:** 2.3.0\r\n\u003c!-- Check whether this is still an issue in the most recent Angular version -->\r\n\r\n* **Browser:** [all ]\r\n\u003c!-- All browsers where this could be reproduced -->\r\n \r\n* **Language:** [all ]\r\n","author":{"url":"https://github.com/wardbell","@type":"Person","name":"wardbell"},"datePublished":"2016-12-21T20:03:48Z","url":"https://github.com/angular/angular/issues/13618"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0c62ffcc-d6df-e598-db95-7875c3017d4e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E6DA:2E3FEE:1BE13D8:234D7AE:6B015286 |
| html-safe-nonce | ce8909e2a9c88d8f3788f2644c9c6fcbdb5c66bdb38afccd06e1dee60d84ea50 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNkRBOjJFM0ZFRToxQkUxM0Q4OjIzNEQ3QUU6NkIwMTUyODYiLCJ2aXNpdG9yX2lkIjoiNDYxMDIxNzg0NTc4MjA0MTIyMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0cb185890a38ceab68ce9ae476b5780fc316e0e71abca9230c9598a1863dbbb1 |
| hovercard-subject-tag | issue:197020617 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/13618/issue_layout |
| twitter:image | https://opengraph.githubassets.com/15e1632295f05335546d706f6210936f7f6b1052198afce3bb36544ce23ea25d/angular/angular/issues/13618 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/15e1632295f05335546d706f6210936f7f6b1052198afce3bb36544ce23ea25d/angular/angular/issues/13618 |
| og:image:alt | I'm submitting a ... (check one with "x") [ ] bug report [x] feature request [ ] support request Current behavior When destroying an injector, Angular has no way AFAIK to inform the service instanc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | wardbell |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width