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

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 Likes

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')

2 Likes

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

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?

1 Like

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

2 Likes