This package has been deprecated

    Author message:

    this version has been deprecated

    sapphire-ioc

    0.0.3 • Public • Published

    Dependencies Build status Coverage Status

    Sapphire IOC

    This is a simple IOC container implementation on NodeJS. You can register services on it and retrieve it later.

    Register with bind

    You can register a service using the bind method and passing a callback on how the service should build when is accessed later. The IOC container will always create a new instance when the ioc.make() is executed.

    // SimpleClass.js
    class SimpleClass {
        constructor(parameter) {
            this._parameter = parameter
        }
     
        getParameter() {
            return this._parameter
        }
     
        setParameter(parameter) {
            this._parameter = parameter
        }
    }
     
    module.exports = SimpleClass
    const IOC = require('sapphire-ioc')
    const SimpleClass = require('./SimpleClass.js')
     
    let ioc = new IOC()
    ioc.bind(SimpleClass, () => (
        new SimpleClass(5)
    ))
    const simpleClass = ioc.make(SimpleClass)

    Register with singleton

    const IOC = require('sapphire-ioc')
    const SimpleClass = require('./SimpleClass.js')
     
    let ioc = new IOC()
    ioc.singleton(SimpleClass, () => (
        new SimpleClass(5)
    ))
    const simpleClass = ioc.make(SimpleClass)
    const simpleClass2 = ioc.make(SimpleClass)
     
    simpleClass.setParameter(3)
    simpleClass2.getParameter()     // 3

    License

    MIT

    Keywords

    Install

    npm i sapphire-ioc

    DownloadsWeekly Downloads

    4

    Version

    0.0.3

    License

    MIT

    Unpacked Size

    111 kB

    Total Files

    15

    Last publish

    Collaborators

    • aleksanderkoko