-
-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change wording for injecting a service #273
Comments
There's nothing stopping you from using inject instead of service. I believe service is just explicit in the guides because you can also inject controllers. |
@rmmmp I update What next? section to reflect documentation should be updated too. |
We alias the name to distinguish from |
Thanks @locks, It sounds like a silver bullet approach to me for 2 reasons:
|
As a counter-argument to your second point: theoretically you could ad-hoc inject anything you like. Addons could chose to export an |
After upgrading from Ember Cli 2.12 to 3.0 I get a lot of errors telling me to
when running ember serve after the upgrade. I have gone trough a lot of these files and updated as told. Should the error notifications say to use |
@pusle I opened an issue to check that problem ember-cli/eslint-plugin-ember#250 |
@Serabe Thank you. |
FWIW, I personally prefer |
I've always thought it was strange that the injection function came from a package of the thing that was being injected. Ideally, I'd want That said, I wonder if anyone every injects something that isn't a service. I know it's possible to inject controllers, but I've personally never done it, and it seems like an anti pattern? |
👍 for May be |
My couple cents - it very much depends on the contexts and approach for DI, but DI shouldn't be aware of what you inject. If it is service, or repository or controller. Less concepts to think about, for the same goal does look better. In the end, everything is a "service". Controllers can be services as well, as they contain logic. const great = inject('great-controller');
const amazing = inject('amazing-service'); In the end, you will use For small context from another framework, from another language. They've started as separation and controllers weren't even injectable. But the way how you can inject something else was always the same. After some time (read 10+ years) more and more patterns were emerging that Controllers can be services too, as they can share what they do and still be "controller" for semantic. So now, you can inject Controller the same way as everything else - services, repositories, controllers, helpers, etc. |
I do think that there is an important distinction here, which is the reason for there being two
You are using two different meanings of the word "service", the general concept of a service, and the particular implementation of
|
As a consumer of API, I do know what I want to inject. Question is - do I need to know, that under the hood, ember is doing something different with this injections? I would vote for no. How I see the goal of DI - I need to be able to get what I've asked for and use it without knowing or relying on special implementation that is doing that. I understand, that there might be some overhead, to understand what was "asked for", eg. was it service or controller, but such overhead should be minimal. I am also probably mixing this RFC for doc changes and some improvements under the hood. |
I also care about this from the perspective of a consumer dev, just trying to write their component that needs a service. Whenever I need to do this, I have to remember that it's technically I would prefer:
Which is certainly confusing from the package's own perspective--to expose a |
This is also something that interferes with tooling. With proper types and a modern editor, if the export were named |
Would it be okay if we close this since we now have #752? Which is in FCP. |
Thanks @bertdeblock! |
When writing route, component, etc. in Ember we often use the Dependency Injection pattern.
Below I'm showing current situation and proposing, what I believe to be, a simpler/more explicit wording than current one.
Current status (Aliasing Method)
Use an alias to explicit what it is.
Proposal (Direct Name)
Use the original method's name as it explicits what it does.
Accessing
Stays the same:
What next?
The text was updated successfully, but these errors were encountered: