New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

ember-cli-dependency-injection-utils

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-cli-dependency-injection-utils

The default blueprint for ember-cli addons.

0.1.0
latest
Version published
Weekly downloads
3
200%
Maintainers
1
Weekly downloads
 
Created

ember-cli-dependency-injection-utils

A utility library for more concise dependency injection through Ember initializers.

Installation

# ember-cli > 0.2.3
ember install ember-cli-dependency-injection-utils
# ember-cli <= 0.2.3
ember install:addon ember-cli-dependency-injection-utils

Usage

Below is a sample initializer file/pattern you might create. For additional info, please check out the source.

Simple example

// app/initializers/dependency-injection.js
import { injectThroughout, injectDeps } from 'ember-cli-dependency-injection-utils';

export function initialize(application) {
  // Inject factory dependencies onto a specific container
  injectDeps(application, 'route', [
    { property: 'api', injectionName: 'service:some-api-client' },
    { property: 'foo', injectionName: 'service:foo-service-you-want-on-every-route' }
  ]);

  // Inject a service to in common Ember places: route, controller, view, component
  injectThroughout(application, 'service:some-ga-analytics-you-need-everywhere');
}

export default { name: 'dependency-injection', initialize };

DRY, real world usage example

// app/initializers/dependency-injection.js
import { injectThroughout, injectDeps } from 'ember-cli-dependency-injection-utils';

export function initialize(application) {
  // Register anything you need
  application.register('config:environment', environment, { singleton: false, instantiate: false });

  // Service definitions
  const environment = { property: 'environment', injectionName: 'config:environment' };
  const routing = { property: 'routing', injectionName: 'service:-routing' };
  const site = { property: 'site', injectionName: 'service:site' };
  const session = { property: 'session', injectionName: 'service:session' };
  const api = { property: 'api', injectionName: 'service:some-api-client' };

  // Inject factory dependencies, using service definitions
  injectDeps(application, 'service:site', [environment]);
  injectDeps(application, 'service:some-api-client', [routing, site, session]);
  injectDeps(application, 'route', [api]);

  // Inject these services in common Ember places
  injectThroughout(application, 'service:site');
  injectThroughout(application, 'service:session');
  injectThroughout(application, 'service:some-ga-analytics');
  injectThroughout(application, 'service:any-service-you-need-everywhere');
}

export default { name: 'dependency-injection', initialize };

TODO

  • Formally document the methods in this README.
  • Write tests!
  • Properly import lodash

Contributors

  • @AO16: Original implementation

Keywords

FAQs

Package last updated on 11 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts