@pion-toolkit/container
v0.2.0
Published
@pion-toolkit/container component of the Pion toolkit.
Downloads
2
Readme
Package: @pion-toolkit/container
An easy-to-use IoC (inversion of control) container.
Installation
To install @pion-toolkit/container
, run:
npm i --save '@pion-toolkit/container'
Usage
import assert from 'assert'
import Container from '@pion-toolkit/container'
const container = new Container()
class Bar {
constructor(foo) {
this.foo = foo
}
}
class FooA {}
class FooB {}
const barKey = Symbol.for('bar')
const fooKey = Symbol.for('foo')
container.bindClass(fooKey, FooA)
container.bindClass(barKey, Bar, { foo: fooKey })
container.contextuallyBindClass(barKey, fooKey, FooB)
const foo = container.resolve(fooKey)
const bar = container.resolve(barKey)
assert(foo instanceof FooA)
assert(bar.foo instanceof FooB)
API
Check out the API documentation.
Author
Jonathan Barronville
License
Apache-2.0
, Apache License, Version 2.0