Difference between using `this.store` and `this.get('store')` within routes


#1

Is there a particular virtue to using this.get('store') versus this.store within routes? I thought I saw this topic discussed here before, so links to the old thread would be great. My agenda is landing on one for that vague notion of “best practices” (more so style consistency).


#2

Technically it doesn’t matter because the store is injected into all Routes and Controllers. However, if that ever changes (unlikely) and/or you switch to store: Ember.inject.service() (or use that in other Ember Objects, such as Components) then you’ll need to use this.get('store'). So, if you want to get into a “safe” habit, use this.get('store')


#3

I see. Thanks for the clarification. This sounds like “lazy loading”.


#4

Does this mean that if you registered your service object in an initializer then you don’t need to follow the

this.get('myService')

pattern?

Is this an essential difference between initialized services vs ad-hoc ones?


#5

@eccegordo i believe so. Although according to the docs, you can also use `this.get(‘myService’) if you use an initializer:

https://guides.emberjs.com/v2.2.0/applications/dependency-injection/