In Ember Classic, container access was like cooties - anything with it could give it to something else in one line.
model() {
const m = getOwner(this).factoryFor('model:foo').create();
// m can inject services
}
Is there a similarly concise idiom for Ember Octane? The following works, but it's much more wordy.
model () {
const owner = getOwner(this);
const Foo = owner.factoryFor('model:foo').class;
const m = new Foo();
setOwner(foo, owner);
}
Is it safer now to use module import syntax in situations like this? I used to avoid it like the plague in Ember Classic because it didn't work with dependency injection. Going that route you get something slightly more palatable, and probably better language server support.
import Foo from 'models/foo'; // 🐉?
model () {
const m = new Foo();
setOwner(foo, getOwner(this));
}