Best practice for using Service


#1

I have a session service that I use around all over my routes and components. I’m now under the dilemma of whether I should inject them in every component that needs them or should I just pass them around like attributes to follow the data down practice.

Question now is:

  1. What’s more expensive in terms of performance, injecting a service or passing only the necessary attributes that you need?
  2. When a service is already declared in a parent component and you also need some of its attributes in the child component, do you inject it in the child component or do you simply pass the necessary attributes?

I’m more inclined to pass the services attributes rather than injecting them to components but I’d like to hear other people’s thoughts.


#2

I am not sure why would injecting service will effect performance in any bit.


#3

Well, I’m not expecting it to slow down the performance. I’m just curious what’s more expensive: injecting vs passing attributes.

If the difference isn’t that much to make anyone bother, then how do you prefer to use service? Do you inject it in every component that needs it or do you simply pass it down if it’s already injected in the parent component?

For me, I pass it down if it’s already injected in the parent components. I just want to know what’s the norm with Ember devs.


#5

Service injection is lazy. So injection would be done when you use it