A platform for community discussion. Free, open, simple.
DEV: Improve `injectServiceIntoService` function
David Taylor2463a8d56851
diff --git a/app/assets/javascripts/discourse/app/pre-initializers/inject-discourse-objects.js b/app/assets/javascripts/discourse/app/pre-initializers/inject-discourse-objects.jsindex 81b0abf5edc..285c2e37fb1 100644--- a/app/assets/javascripts/discourse/app/pre-initializers/inject-discourse-objects.js+++ b/app/assets/javascripts/discourse/app/pre-initializers/inject-discourse-objects.js@@ -8,12 +8,18 @@ import User from "discourse/models/user";const ALL_TARGETS = ["controller", "component", "route", "model", "adapter"];-function injectServiceIntoService({ container, app, property, specifier }) {+function injectServiceIntoService({ app, property, specifier }) {// app.inject doesn't allow implicit injection of services into services.// However, we need to do it in order to convert our old service-like objects// into true services, without breaking existing implicit injections.// This hack will be removed when we remove implicit injections for the Ember 4.0 update.- container.lookup(specifier);++ // Supplying a specific injection with the same property name prevents the infinite+ // which would be caused by injecting a service into itself+ app.register("discourse:null", null, { instantiate: false });+ app.inject(specifier, property, "discourse:null");++ // Bypass the validation in `app.inject` by adding directly to the arrayapp.__registry__._typeInjections["service"].push({property,specifier,@@ -64,20 +70,17 @@ export default {app.inject("service", "session", "session:main");injectServiceIntoService({- container,app,property: "messageBus",specifier: "service:message-bus",});injectServiceIntoService({- container,app,property: "siteSettings",specifier: "service:site-settings",});app.inject("service", "topicTrackingState", "topic-tracking-state:main");injectServiceIntoService({- container,app,property: "keyValueStore",specifier: "service:key-value-store",