Best Practices: accessing app config from addon code

I’ve been using Ember.getOwner(this).resolveRegistration in my addons for a while and it works great.

let config = Ember.getOwner(this).resolveRegistration('config:environment');

this is generally referred to a component or a route or a service.

1 Like

I’ve been using getOwner now too for a while.

But recently I ran into a project that has travis scenarios that include ember versions < 2.3, where getOwner is not available. Is there a way to include a polyfill or shim for those versions to fix this?

I did see https://github.com/rwjblue/ember-getowner-polyfill but that relies on you actually using an import, while I would like to only include something for the < 2.3 versions

appInstance.resolveRegistration(‘config:environment’); worked great for me

1 Like

Thanks @ykaragol it worked like a charm

In modern Ember you don’t use Ember global anymore. There is a module import for getOwner instead:

import { getOwner } from '@ember/application';

getOwner(this).resolveRegistration('config:environment');
2 Likes