A framework-agnostic dependency container.
$ npm add @aldojs/container
let { createContainer } = require('@aldojs/container')
let container = createContainer()
// add a `foo` factory
container.bind('foo', (c) => ({ foo: true }))
// later, create `foo` object
let obj = container.make('foo')
Check a bind is already defined.
Add an new factory into the container.
Bind a singleton factory to make a singleton instances.
Create and return the service instance, passing the additional arguments.
Each function given to bind
or singleton
as second parameter should have the following signature
function Factory = (c: Container, ...args: any[]) => any;