Is this right? I have an Ember service with routing injected as service

I have inherited an application built on Ember 2.13. I came across an error handling service that had the following:

export default Ember.Service.extend({
    routing: Ember.inject.service('-routing'),

The idea is that this service routes to an error page when necessary. (This is part of the application’s global error handling.)

Is this acceptable? Are there any caveats to using this in a service? Is there a better way to accomplish routing from a service?

Thanks in advance!

There isn’t anything wrong with redirecting with the router service from a different service. However, the specific syntax you shared shouldn’t be necessary to reference -routing - you should be able to just do the following (I think from mid-2.x versions on the router service is available).

router: Ember.inject.service()

Yeah I believe the -routing one is the private router service which you should probably avoid using if you can use the public one instead. As for whether you should use the routing service in another service I’d say generally the routing service was exposed for exactly that reason: so you didn’t have to use private APIs or other hacks to route from components/services/etc.

Thanks so much for the advice! Time to add another change to my backlog…