ember-container
v0.0.3
Published
ember owner as destructable object
Downloads
0
Readme
Containers for Ember
The dependency injection in ember works through the Owner
. An object on
which objects can be registered and later on looked up. It doesn't have the most
convenient API when passing around the owner as "container" for dependencies.
Here comes ember-container
into play. A wrapper around owner for a nicer API
to embers DI.
Example
Let's say we want to access isAuthenticated
from session
service from
ember-simple-auth
in a
function.
function canLogin({ services }) {
const { session } = services;
return session.isAuthenticated;
}
which we invoke from a component:
import { getOwner } from '@ember/application';
import Component from '@glimmer/component';
import makeContainer from 'ember-container';
export default class MyComponent extends Component {
get canLogin() {
return canLogin(makeContainer(getOwner(this)));
}
}
Whilst this is more of a showcase to demo its usage; at best, this is used as a
low-level API as part of your libraries that pipe through the Owner
into
userland code.
Installation
tbd.