@secjs/ioc
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

IoC Container 📦

Very simple IoC container for NodeJS

GitHub followers GitHub stars

Buy Me A Coffee

GitHub language count Repository size License Commitizen

The intention behind this repository is to always maintain a viable and simple IoC to use in any type of NodeJS applications, with or without Frameworks

Installation

npm install @secjs/ioc

Usage

Set

Container can register dependencies for you, every container.get will create a new instance for UserService.

import { Container } from '@SecJS/IoC'
import { UserService } from 'app/Services/UserService'

const container = new Container()

container.set(UserService)
const userService = container.get<UserService>('UserService', 'props', 'to', 'UserService Constructor here')

console.log(userService.findAll())

Singleton

Container can register singleton dependencies, when singleton container.get will return the same UserService instance all time.

import { Container } from '@SecJS/IoC'
import { UserService } from 'app/Services/UserService'

const container = new Container()

container.singleton(UserService, 'props', 'to', 'UserService Constructor here')
const userService = container.get<UserService>('UserService')

console.log(userService.findAll())

Singleton can register static objects and arrays too, but for arrays and objects the name is required:

container.singleton([], 'myArray')
container.singleton({}, 'myObject')

console.log(container.get('myArray')) // []
console.log(container.get('myObject')) // {}

License

Made with 🖤 by jlenon7 👋

Dependencies (0)

    Dev Dependencies (28)

    Package Sidebar

    Install

    npm i @secjs/ioc

    Weekly Downloads

    2

    Version

    1.0.8

    License

    MIT

    Unpacked Size

    10.4 kB

    Total Files

    11

    Last publish

    Collaborators

    • jlenon7