ember-container
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i ember-container

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

7.24 kB

Total Files

6

Last publish

Collaborators

  • gossi