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

1.0.0 • Public • Published

DI Container & Builder

Getting Started

class Car {
	/**
	 * Creates instance of Car,
	 * expects 1 parameter object argument with dependencies
	 * 
	 * @param {object} dependencies
	 * @param {Engine} dependencies.engine
	 */
	constructor({ engine }) {
		this._engine = engine;
	}
}

class Engine { }
const { ContainerBuilder } = require('di6');

const builder = new ContainerBuilder();

// Give the `Engine` type an alias that will be used for dependency resolving
builder.register(Engine)
	.as('engine')
	.asInstancePerDependency();

const container = builder.container();

const car = container.createInstance(Car); // instanceOf Car
car._engine; // instanceOf Engine

Package Sidebar

Install

npm i di0

Weekly Downloads

53

Version

1.0.0

License

MIT

Unpacked Size

34.7 kB

Total Files

26

Last publish

Collaborators

  • snatalenko