How to inject a service in discourse?

The problem here is that the ‘connector’ is not an EmberObject, and so you can’t inject things into it. Instead, you’ll need to create an Ember Component and inject it there.

Your ‘connector’ template would then look something like

{{my-component-name}}

Here’s an example of how that’s done in the whos-online plugin:

We have a service in core:

A connector template in the plugin

The component definition:
https://github.com/discourse/discourse-whos-online/blob/main/assets/javascripts/discourse/components/whos-online.js#L6-L7

(or you can use export default Component.extend({ whosOnline: service() }) if you prefer)

And the component template:
https://github.com/discourse/discourse-whos-online/blob/main/assets/javascripts/discourse/templates/components/whos-online.hbs