Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rinoldsimon opened this issue Apr 20, 2021 · 3 comments · May be fixed by #339
Open

Comments

@rinoldsimon
Copy link

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
Copy link
Author

According to #257 (comment) the docs https://ember-cli-notifications.netlify.app/ needs to be updated ?

@pichfl
Copy link
Contributor

pichfl commented Sep 17, 2021

The docs reflect the expected service name by now 👍

@jacobq
Copy link
Contributor

jacobq commented May 26, 2022

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
    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:

    application.inject(injectionTarget, 'notifications', 'notification-messages:service');

  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:

jacobq added a commit to jacobq/ember-cli-notifications that referenced this issue May 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants