Title: `inject` and `directiveInject` need bridging when used with `Component.provides` · Issue #23330 · angular/angular · GitHub
Open Graph Title: `inject` and `directiveInject` need bridging when used with `Component.provides` · Issue #23330 · angular/angular
X Title: `inject` and `directiveInject` need bridging when used with `Component.provides` · Issue #23330 · angular/angular
Description: Currently we generate inject for @Injectable and directiveInject for @Component and @Directive. This works fine since @Injectable declared as part of @NgModule does not need to see anything from the Element Injector Tree. However this do...
Open Graph Description: Currently we generate inject for @Injectable and directiveInject for @Component and @Directive. This works fine since @Injectable declared as part of @NgModule does not need to see anything from th...
X Description: Currently we generate inject for @Injectable and directiveInject for @Component and @Directive. This works fine since @Injectable declared as part of @NgModule does not need to see anything from th...
Opengraph URL: https://github.com/angular/angular/issues/23330
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`inject` and `directiveInject` need bridging when used with `Component.provides`","articleBody":"Currently we generate `inject` for `@Injectable` and `directiveInject` for `@Component` and `@Directive`. This works fine since `@Injectable` declared as part of `@NgModule` does not need to see anything from the Element Injector Tree.\r\n\r\nHowever this does not work in the case when `@Injectable` is used with `@Component.providers` (or `@Component.viewProviders`) because in that case the `@Injectable` can see into the Element Injector Tree.\r\n\r\n## Possible fixes are:\r\n\r\n### Mark services in `@Component.providers` using `inject` (:thumbsdown:)\r\n\r\nnon-starter as it breaks locality.\r\n\r\n### Have only one `inject` (:thumbsdown:)\r\n\r\nThis would require merging `directiveInject` into `inject`\r\n\r\nPros: \r\n- Easy to implement\r\n\r\nCons:\r\n- `di` will have to know about `render3`\r\n- Breaks tree shaking since any `@Injectable` will be pulling in at least some code of `render3`.\r\n\r\n### Have `ComponentDefFeature` which would patch `inject` to act like `directiveInject` only when `@Component.providers` are used (:thumbsup:)\r\n\r\nPros:\r\n- Tree shaking works as expected.\r\n- `di` does not need to know about `render3` (needs to have a hook, see *cons*)\r\n\r\nCons:\r\n- `di` has to have a hook into which external `render3` can connect in order to redirect `inject` into `directiveInject`. Since this is a private hook, it should be small cost.\r\n\r\n## Syntax\r\n\r\n```\r\n@Inejctable()\r\nclass SomeService {\r\n constructor(dep: SomeDep) {}\r\n static ngInjectableDef = defineInjectable({\r\n factory: () => new SomeService(inject(SomeDep));\r\n });\r\n}\r\n\r\n@Component({\r\n ...,\r\n provides: [SomeService]\r\n})\r\nclass MyComponent {\r\n static ngComponentDef = defineCompoent({\r\n ...,\r\n provides: [SomeService],\r\n features: [ComponetProvidersFeature]\r\n });\r\n}\r\n```\r\n\r\n`ComponetProvidersFeature` would than use some private API to patch the `inject` to go through the `directiveInject` in cases where the factory is called as a consequence of `@Component.providers`.","author":{"url":"https://github.com/mhevery","@type":"Person","name":"mhevery"},"datePublished":"2018-04-11T23:42:23Z","url":"https://github.com/angular/angular/issues/23330"}
| 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:bed0fbb4-2b82-a161-5bc2-f8292faf9559 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AEAC:33444D:2444122:303AC77:6B0199C0 |
| html-safe-nonce | 0df95f4785065bd695f4d5c5e0fbf9e8a8a82cba42a5faf182181650ad0fd798 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRUFDOjMzNDQ0RDoyNDQ0MTIyOjMwM0FDNzc6NkIwMTk5QzAiLCJ2aXNpdG9yX2lkIjoiNzI5Nzc0MDIxOTA0MDc2NjQwMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1d76296c708bf90ececd60b6b51b57047d7789405219c4a845fa77d5751c7c1f |
| hovercard-subject-tag | issue:313525743 |
| 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/23330/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f810d6dedff3c23b551aefc005fb8997ad9353c80f9aa4bcf6c4a36e70bf507f/angular/angular/issues/23330 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f810d6dedff3c23b551aefc005fb8997ad9353c80f9aa4bcf6c4a36e70bf507f/angular/angular/issues/23330 |
| og:image:alt | Currently we generate inject for @Injectable and directiveInject for @Component and @Directive. This works fine since @Injectable declared as part of @NgModule does not need to see anything from th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mhevery |
| 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