René's URL Explorer Experiment


Title: [Proposal] Defining non-singleton services or component's service · Issue #18015 · angular/angular · GitHub

Open Graph Title: [Proposal] Defining non-singleton services or component's service · Issue #18015 · angular/angular

X Title: [Proposal] Defining non-singleton services or component's service · Issue #18015 · angular/angular

Description: Context So I found a nice way to compose my Directives/Components. I use a service that's not part of any module but just defined at Directive/Component level. Here is an example : @Component({ providers: [ NgrxService ] }) export class ...

Open Graph Description: Context So I found a nice way to compose my Directives/Components. I use a service that's not part of any module but just defined at Directive/Component level. Here is an example : @Component({ pro...

X Description: Context So I found a nice way to compose my Directives/Components. I use a service that's not part of any module but just defined at Directive/Component level. Here is an example : @Component({...

Opengraph URL: https://github.com/angular/angular/issues/18015

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Proposal] Defining non-singleton services or component's service","articleBody":"## Context\r\nSo I found a nice way to compose my Directives/Components. I use a service that's not part of any module but just defined at Directive/Component level.\r\n\r\nHere is an example :\r\n```ts\r\n@Component({\r\n  providers: [ NgrxService ]\r\n})\r\nexport class MyComponent {\r\n  constructor( @Self() private ngrx: NgrxService) { }\r\n}\r\n```\r\nSo `NgrxService` is not meant to be a singleton service but rather a way to compose my Component with reusable code. The service look like this : \r\n\r\n```ts\r\n@Injectable()\r\nexport class NgrxService {\r\n  constructor(private store: Store, private cdr: ChangeDetectionRef) {\r\n  }\r\n\r\n  select() { ... }\r\n  dispatch() { ... }\r\n  set() { ... }\r\n\r\n  ngOnDestroy(){\r\n    ....\r\n  }\r\n}\r\n```\r\n*I'm also talking about that kind of service here #17948*.\r\n\r\nThis is really handy because you can inject Directive/Component related stuff like `ViewContainerRef`, `ChangeDetectorRef`... and you have even access to `ngOnDestroy` life cycle hook.\r\nSo it's wonderful and everything work great but....\r\n\r\n## Problem\r\nThe catch is that you have to always provide the service for each component, if you happen to forget it you'll probably end up with a parent service which you absolutely don't want. You can use `@Self()` to protect from it but well if you forget to provide it you'll probably also forget to use `@Self()`. \r\nEven if you have a really good memory it's still boilerplate and it feels like we're doing the job at the wrong end. The service is meant to work like that so that behavior should be determined during the service definition and not during its usage.\r\n\r\n## Proposals\r\nThere is probably multiple ways of achieving this but here is my proposal :\r\nCreate a new decorator for that kind of service:\r\n1. Those service won't be singleton but a new instance will be created for each injection.\r\n2. Can't be injected elsewhere than inside Component or Directive and get the same life cycle as the host Component / Directive.\r\n3. Must be provided by the component/directive's module or part of an imported module (do we need to export it ?). Their injection is scoped to the module and not global (like Component, Directive and Pipe).\r\n\r\n## Update\r\nSince v6, this proposal is now about adding a `component` value to `providedIn`.","author":{"url":"https://github.com/ghetolay","@type":"Person","name":"ghetolay"},"datePublished":"2017-07-08T16:50:53Z","url":"https://github.com/angular/angular/issues/18015"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:51da7dfe-e1b6-4174-5fda-973c837b1640
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8632:4BB79:19DD3FC:20FAD35:6B014FC7
html-safe-nonce2fb163e9cc61d8a767d6427681e9896c8f94050c3952cf6cde07fada99d028c1
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjMyOjRCQjc5OjE5REQzRkM6MjBGQUQzNTo2QjAxNEZDNyIsInZpc2l0b3JfaWQiOiI1MjE2MTg0NTIwODk3ODEwMzc2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac010056d7eea2af2a58b823f38c83bb537fcd6a75026bff667e1953a8a1096524
hovercard-subject-tagissue:241465332
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/18015/issue_layout
twitter:imagehttps://opengraph.githubassets.com/70541052008ccd7e80a7232d2aa12a42c44ea7db190e478d5762b5d6b5409f0a/angular/angular/issues/18015
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/70541052008ccd7e80a7232d2aa12a42c44ea7db190e478d5762b5d6b5409f0a/angular/angular/issues/18015
og:image:altContext So I found a nice way to compose my Directives/Components. I use a service that's not part of any module but just defined at Directive/Component level. Here is an example : @Component({ pro...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameghetolay
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/angular/angular git https://github.com/angular/angular.git
octolytics-dimension-user_id139426
octolytics-dimension-user_loginangular
octolytics-dimension-repository_id24195339
octolytics-dimension-repository_nwoangular/angular
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id24195339
octolytics-dimension-repository_network_root_nwoangular/angular
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/angular/angular/issues/18015#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F18015
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F18015
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=angular%2Fangular
Reloadhttps://github.com/angular/angular/issues/18015
Reloadhttps://github.com/angular/angular/issues/18015
Reloadhttps://github.com/angular/angular/issues/18015
angularhttps://github.com/angular
angularhttps://github.com/angular/angular
Codehttps://github.com/angular/angular
Issues836 (836)https://github.com/angular/angular/issues
Pull requests141 (141)https://github.com/angular/angular/pulls
Discussionshttps://github.com/angular/angular/discussions
Actionshttps://github.com/angular/angular/actions
Projectshttps://github.com/angular/angular/projects
Security and quality40 (40)https://github.com/angular/angular/security
Insightshttps://github.com/angular/angular/insights
https://github.com/angular/angular
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/18015
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/18015
[Proposal] Defining non-singleton services or component's servicehttps://github.com/angular/angular/issues/18015#top
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
core: dihttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20di%22
featureLabel used to distinguish feature request from other issueshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22feature%22
feature: under considerationFeature request for which voting has completed and the request is now under considerationhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22feature%3A%20under%20consideration%22
Backloghttps://github.com/angular/angular/milestone/82
https://github.com/ghetolay
ghetolayhttps://github.com/ghetolay
on Jul 8, 2017https://github.com/angular/angular/issues/18015#issue-241465332
#17948https://github.com/angular/angular/pull/17948
Nexthttps://github.com/angular/angular/issues/18015?timeline_page=1
https://github.com/mlc-mlapis
mlc-mlapishttps://github.com/mlc-mlapis
on Jul 8, 2017https://github.com/angular/angular/issues/18015#issuecomment-313871915
@Injectablehttps://github.com/Injectable
https://github.com/ghetolay
ghetolayhttps://github.com/ghetolay
on Jul 8, 2017https://github.com/angular/angular/issues/18015#issuecomment-313885260
https://github.com/mlc-mlapis
mlc-mlapishttps://github.com/mlc-mlapis
on Jul 8, 2017https://github.com/angular/angular/issues/18015#issuecomment-313886107
https://github.com/trotyl
trotylhttps://github.com/trotyl
on Jul 9, 2017https://github.com/angular/angular/issues/18015#issuecomment-313894575
https://github.com/ghetolay
ghetolayhttps://github.com/ghetolay
on Jul 9, 2017https://github.com/angular/angular/issues/18015#issuecomment-313910319
https://github.com/trotyl
trotylhttps://github.com/trotyl
on Jul 9, 2017https://github.com/angular/angular/issues/18015#issuecomment-313910750
@ghetolayhttps://github.com/ghetolay
https://github.com/trotyl
trotylhttps://github.com/trotyl
on Jul 9, 2017https://github.com/angular/angular/issues/18015#issuecomment-313911351
https://github.com/trotyl
trotylhttps://github.com/trotyl
on Jul 9, 2017https://github.com/angular/angular/issues/18015#issuecomment-313913086
DI feature: lifecycle hooks for services, especially OnDestroy #13618https://github.com/angular/angular/issues/13618
Confusing DI behavior for ChangeDetectorRef #14656https://github.com/angular/angular/issues/14656
DI: Explicit instance scope (singleton, prototype,..) #17017https://github.com/angular/angular/issues/17017
[Feature Request] Provide Default Constructor Injection Without Configuration Boilerplate #17188https://github.com/angular/angular/issues/17188
https://github.com/ghetolay
ghetolayhttps://github.com/ghetolay
on Jul 9, 2017https://github.com/angular/angular/issues/18015#issuecomment-313935039
#17017https://github.com/angular/angular/issues/17017
https://github.com/trotyl
trotylhttps://github.com/trotyl
on Jul 10, 2017https://github.com/angular/angular/issues/18015#issuecomment-313989624
https://github.com/ghetolay
ghetolayhttps://github.com/ghetolay
on Jul 10, 2017https://github.com/angular/angular/issues/18015#issuecomment-314052347
https://github.com/trotyl
trotylhttps://github.com/trotyl
on Jul 10, 2017https://github.com/angular/angular/issues/18015#issuecomment-314066280
@Injectablehttps://github.com/Injectable
IgorMinarhttps://github.com/IgorMinar
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
on Jul 10, 2017https://github.com/angular/angular/issues/18015#event-1157839307
chuckjazhttps://github.com/chuckjaz
featureLabel used to distinguish feature request from other issueshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22feature%22
on Jul 24, 2017https://github.com/angular/angular/issues/18015#event-1176460848
https://github.com/igabesz
igabeszhttps://github.com/igabesz
on Oct 4, 2017https://github.com/angular/angular/issues/18015#issuecomment-334291439
https://stackoverflow.com/questions/46573239/https://stackoverflow.com/questions/46573239/
https://github.com/ghetolay
ghetolayhttps://github.com/ghetolay
on May 4, 2018https://github.com/angular/angular/issues/18015#issuecomment-386602414
https://github.com/trotyl
trotylhttps://github.com/trotyl
on May 6, 2018https://github.com/angular/angular/issues/18015#issuecomment-386858923
https://github.com/simeyla
simeylahttps://github.com/simeyla
on Aug 14, 2018https://github.com/angular/angular/issues/18015#issuecomment-413044490
@selfhttps://github.com/self
https://github.com/bryce-marshall
bryce-marshallhttps://github.com/bryce-marshall
on Nov 21, 2018https://github.com/angular/angular/issues/18015#issuecomment-440481960
@ghetolayhttps://github.com/ghetolay
herehttps://softwareengineering.stackexchange.com/questions/381783/angular-7-injecting-a-state-context-snapshot
https://github.com/jsgoupil
jsgoupilhttps://github.com/jsgoupil
on Feb 16, 2019https://github.com/angular/angular/issues/18015#issuecomment-464391373
https://stackoverflow.com/questions/54726855/how-to-clear-the-provider-cache-to-use-with-usefactory-in-angular-7https://stackoverflow.com/questions/54726855/how-to-clear-the-provider-cache-to-use-with-usefactory-in-angular-7
https://github.com/mlc-mlapis
mlc-mlapishttps://github.com/mlc-mlapis
on Feb 16, 2019https://github.com/angular/angular/issues/18015#issuecomment-464398888
@jsgoupilhttps://github.com/jsgoupil
https://github.com/jsgoupil
jsgoupilhttps://github.com/jsgoupil
on Feb 17, 2019https://github.com/angular/angular/issues/18015#issuecomment-464401563
@mlc-mlapishttps://github.com/mlc-mlapis
https://github.com/pauldraper
pauldraperhttps://github.com/pauldraper
on Apr 1, 2019https://github.com/angular/angular/issues/18015#issuecomment-478605458
https://github.com/trotyl
trotylhttps://github.com/trotyl
on Apr 16, 2019https://github.com/angular/angular/issues/18015#issuecomment-483613591
@pauldraperhttps://github.com/pauldraper
pkozlowski-opensourcehttps://github.com/pkozlowski-opensource
core: dihttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20di%22
on Mar 12, 2020https://github.com/angular/angular/issues/18015#event-3123453869
angular-robothttps://github.com/apps/angular-robot
feature: under considerationFeature request for which voting has completed and the request is now under considerationhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22feature%3A%20under%20consideration%22
on Jun 4, 2021https://github.com/angular/angular/issues/18015#event-4843554841
https://github.com/alxhub
alxhubhttps://github.com/alxhub
on Apr 14, 2022https://github.com/angular/angular/issues/18015#issuecomment-1099725154
alxhubhttps://github.com/alxhub
completedhttps://github.com/angular/angular/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Apr 14, 2022https://github.com/angular/angular/issues/18015#event-6437886381
https://github.com/apps/angular-automatic-lock-bot
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on May 15, 2022https://github.com/angular/angular/issues/18015#issuecomment-1126970846
automatic conversation locking policyhttps://github.com/angular/angular/blob/8f24bc9443b3872fe095d9f7f77b308a361a13b4/docs/GITHUB_PROCESS.md#conversation-locking
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on May 15, 2022https://github.com/angular/angular/issues/18015#event-6611514464
Sign up for freehttps://github.com/signup?return_to=https://github.com/angular/angular/issues/18015
Sign in to commenthttps://github.com/login?return_to=https://github.com/angular/angular/issues/18015
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
core: dihttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20di%22
featureLabel used to distinguish feature request from other issueshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22feature%22
feature: under considerationFeature request for which voting has completed and the request is now under considerationhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22feature%3A%20under%20consideration%22
BacklogNo due datehttps://github.com/angular/angular/milestone/82
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.