Skip to content

aldojs/container

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A framework-agnostic dependency container.

Install

$ npm add @aldojs/container

Usage

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')

API

container.bound(name)

Check a bind is already defined.

container.bind(name, fn)

Add an new factory into the container.

container.singleton(name, fn)

Bind a singleton factory to make a singleton instances.

container.make(name, ...args)

Create and return the service instance, passing the additional arguments.

Factory function

Each function given to bind or singleton as second parameter should have the following signature

function Factory = (c: Container, ...args: any[]) => any;

About

Framework-agnostic dependency container

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy