mansona / ember-cli-notifications

⚛ Atom inspired notification messages for ember-cli
https://ember-cli-notifications.netlify.app/
MIT License
177 stars 94 forks source link

Assertion Failed: Attempting to inject an unknown injection: 'service:notification-messages' #311

Open rinoldsimon opened 3 years ago

rinoldsimon commented 3 years ago

Error: Assertion Failed: Attempting to inject an unknown injection: 'service:notification-messages'

Code: initializer/inject-notifications.js

export function initialize( application ) {
  ['controller', 'component', 'route'].forEach(injectionTarget => {
    application.inject(injectionTarget, 'notifications', 'notification-messages:service');
  });
}

export default {
  name: 'inject-notifications',
  initialize
};

Ember - 3.26.1 "ember-cli-notifications": "^6.3.4",

rinoldsimon commented 3 years ago

According to https://github.com/mansona/ember-cli-notifications/issues/257#issuecomment-823407763 the docs https://ember-cli-notifications.netlify.app/ needs to be updated ?

pichfl commented 2 years ago

The docs reflect the expected service name by now 👍

jacobq commented 2 years ago

I know that using @service notifications; in a class works just fine. I'm less familiar with the manual injection done via initializer, but I'm pretty sure there are at least 2 problems here:

  1. The docs site gives an example of injecting with the injectionName of notification-messages:service, which looks like a typo to me. Run as written on a minimal Ember 3.28.x app results in the error in the OP:

    Uncaught Error: Assertion Failed: Attempting to inject an unknown injection: 'notifications:service' at assert (index.js:178:1) at Registry.proto.validateInjections (index.js:1094:1) at processInjections (index.js:380:1) at buildInjections (index.js:407:1) at injectionsFor (index.js:422:1) at FactoryManager.create (index.js:510:1) at Proxy.create (index.js:250:1) at instantiateFactory (index.js:351:1) at lookup (index.js:279:1) at Container.lookup (index.js:144:1)

    It should be service:notifications like this:

    Example initializer ```js export function initialize(application) { // Works in 3.x but gives deprecations warning [deprecation id: implicit-injections] // Stops working in 4.x though still helpfully gives a deprecation warning application.inject('controller', 'notifications', 'service:notifications'); // These don't work because the names of the things being injected aren't recognized/registered //application.inject('controller', 'notifications', 'service:notification-messages'); //application.inject('controller', 'notifications', 'notifications:service'); } export default { initialize, }; ```

    not like this: https://github.com/mansona/ember-cli-notifications/blob/136e6c6edb694c4f62fee021963e0b0e270a8188/tests/dummy/app/templates/application.hbs#L45

  2. Typo aside, the docs should not suggest using implicit injection since it is no longer recommended and doesn't even work in ember v4.x.

    DEPRECATION: As of Ember 4.0.0, owner.inject no longer injects values into resolved instances, and calling the method has been deprecated. Since this method no longer does anything, it is fully safe to remove this injection. As an alternative to this API, you can refactor to explicitly inject notifications on route, or look it up directly using the getOwner API. [deprecation id: remove-owner-inject] See https://deprecations.emberjs.com/v4.x#toc_implicit-injections for more details.

    See also: