@kayo wrote:
Suppose an app has 2 services:
service:log
service:foo
where
foo
wants to uselog
.Suppose we want all services to be able to log and if in an initializer we did:
application.inject('service', 'log', 'service:log')
Ember throws: Error: Cannot inject aservice:log
on other service(s).But we can inject
log
only onfoo
:
application.inject('service:foo', 'log', 'service:log')
which works.This brought up some questions:
From a design point of view what impact would it have to inject a service on another service? Is it better avoided?
Instead of a service, we can use a log
util
which maybe be a plain JavaScript object holding functions saylog.info()
andlog.error()
.
Then, import it:
import log from 'my-app/utils/log'
and invoke it:
log.error('An error occurred.')
Wouldn't this also be a solution. (btw, in this case, willlog
no longer be a singleton if imported in multiple files?)Just trying to better understand this. Would be great if anyone could point out pros and cons. Thanks.
Posts: 1
Participants: 1