Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dicontainer

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dicontainer

Simple dependency container

  • 0.2.2
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

#dicontainer

Tiny dependency container

  • Handles resolution of dependencies
  • Lazy instantiation (services arent created until they are needed)
  • Understands Angular.js providers/services/factories/globals
  • Provides simple React.js compatible Mixin for attaching services
  • Tests for circular dependencies
  • less than 1kb (gzipped)

###Basic Usage

####Setup

var Container = require('dicontainer');

var appContainer = new Container(logFunction /* optional */);

####Registration

container.register(name, factory /* or service/provider */);


function MathService(other) {}
MathService.prototype.add = function (a,b) { return a+b; };
MathService.$inject = ['OtherService']; 

appContainer.register('MathService', MathService); // Dependencies are read from $inject property

// --- or ----

function MathService(other) {}
MathService.prototype.add = function (a,b) { return a+b; };

appContainer.register('MathService', MathService, ['OtherService']); // Dependencies are specified as array

// --- or ----

function MathService(other) {}
MathService.prototype.add = function (a,b) { return a+b; };

appContainer.register('MathService', ['OtherService', MathService]); // Dependencies and service are specified as array

####Resolution

var instance = container.resolve(name);


var MathService = appContainer.resolve('MathService');
MathService.add(1,2);

####Mixin

Service instances are attached to this.services

var Calculator = React.createClass({
	
	mixins: [appContainer.Mixin('MathService', 'OtherService')]

	render: function () {
		this.services.MathService.add()
	}
});

####Building & testing

npm run build // lint, test & compile dist
npm test // test in terminal
npm run test-local // run test in browser

Keywords

FAQs

Package last updated on 21 Mar 2014

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc