Skip to content

Conversation

NullVoxPopuli
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli commented Jun 23, 2025

Propose Make @service able to be used in templates

Summary

This pull request is proposing a new RFC.

To succeed, it will need to pass into the Exploring Stage, followed by the Accepted Stage.

A Proposed or Exploring RFC may also move to the Closed Stage if it is withdrawn by the author or if it is rejected by the Ember team. This requires an "FCP to Close" period.

An FCP is required before merging this PR to advance to Accepted.

Upon merging this PR, automation will open a draft PR for this RFC to move to the Ready for Released Stage.

Exploring Stage Description

This stage is entered when the Ember team believes the concept described in the RFC should be pursued, but the RFC may still need some more work, discussion, answers to open questions, and/or a champion before it can move to the next stage.

An RFC is moved into Exploring with consensus of the relevant teams. The relevant team expects to spend time helping to refine the proposal. The RFC remains a PR and will have an Exploring label applied.

An Exploring RFC that is successfully completed can move to Accepted with an FCP is required as in the existing process. It may also be moved to Closed with an FCP.

Accepted Stage Description

To move into the "accepted stage" the RFC must have complete prose and have successfully passed through an "FCP to Accept" period in which the community has weighed in and consensus has been achieved on the direction. The relevant teams believe that the proposal is well-specified and ready for implementation. The RFC has a champion within one of the relevant teams.

If there are unanswered questions, we have outlined them and expect that they will be answered before Ready for Release.

When the RFC is accepted, the PR will be merged, and automation will open a new PR to move the RFC to the Ready for Release stage. That PR should be used to track implementation progress and gain consensus to move to the next stage.

Checklist to move to Exploring

  • The team believes the concepts described in the RFC should be pursued.
  • The label S-Proposed is removed from the PR and the label S-Exploring is added.
  • The Ember team is willing to work on the proposal to get it to Accepted

Checklist to move to Accepted

  • This PR has had the Final Comment Period label has been added to start the FCP
  • The RFC is announced in #news-and-announcements in the Ember Discord.
  • The RFC has complete prose, is well-specified and ready for implementation.
    • All sections of the RFC are filled out.
    • Any unanswered questions are outlined and expected to be answered before Ready for Release.
    • "How we teach this?" is sufficiently filled out.
  • The RFC has a champion within one of the relevant teams.
  • The RFC has consensus after the FCP period.

@github-actions github-actions bot added the S-Proposed In the Proposed Stage label Jun 23, 2025
- **API Surface**: Another way to access services
- **Template Verbosity**: `{{#let}}` adds nesting for method calls

## Alternatives
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write about how service can actually be a resource


Add helper manager capabilities to `@ember/service`'s `service` export, enabling direct template usage while maintaining backward compatibility with existing service injection patterns.

## Motivation
Copy link
Contributor Author

@NullVoxPopuli NullVoxPopuli Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain why service can't just work with the default helper manager (default helper manager doesn't know about the owner)

  • re-shaping services as resources would solves this (internal change)

alternatively, we could make the default helper manager setOwner on the function
(then we don't need a separate helper manager)

@ef4
Copy link
Contributor

ef4 commented Jun 27, 2025

Discussed during RFC review. No opposition to this design, but also interested in ways to make service-access possible in the JS scope using a more resource-based or cell-like API.

@NullVoxPopuli NullVoxPopuli added S-Exploring In the Exploring RFC Stage and removed S-Proposed In the Proposed Stage labels Jul 11, 2025
Comment on lines +39 to +49
import Component from '@glimmer/component';
import { service } from '@ember/service';

export default class extends Component {
@service theme;

// Boilerplate just to expose the service
get exposedTheme() {
return this.theme;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why making the example more verbose than it needs to be?
In the HBS, the Service could be reached via just this.theme.

Suggested change
import Component from '@glimmer/component';
import { service } from '@ember/service';
export default class extends Component {
@service theme;
// Boilerplate just to expose the service
get exposedTheme() {
return this.theme;
}
}
import Component from '@glimmer/component';
import { service } from '@ember/service';
export default class extends Component {
@service theme;
}

@vlascik
Copy link

vlascik commented Aug 18, 2025

Btw there's already https://github.com/buschtoens/ember-service-helper and it can also return bound methods https://github.com/buschtoens/ember-service-helper/blob/main/addon/helpers/service.js . Not sure how useful that is.

@NullVoxPopuli
Copy link
Contributor Author

aye, I have something similar here: https://github.com/universal-ember/ember-primitives/blob/main/ember-primitives/src/helpers/service.ts

bound methods

method invocation not working from templates without being bound is considered a bug and its one of my top to-dos to fix once the monorepos merge.

@kategengler
Copy link
Member

kategengler commented Aug 22, 2025

RFC Review: What do the types look like? Does it work in template, as a decorator, and with stable decorators?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-Exploring In the Exploring RFC Stage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants