Wondering what’s next for npm?Check out our public roadmap! »

    js-service-container
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.1 • Public • Published

    JavaScript Container

    Build Status

    A simple and minimalistic and service container for JavaScript and TypeScript.

    Usage

    Start with building the container:

    import {ContainerBuilder, SingletonService} from 'js-service-container';
     
    const builder = new ContainerBuilder()
     
    builder.singleton('class-a', container => {
      return new ClassA()
    })
     
    builder.singleton('class-b', container => {
      return new ClassB(container.get('class-a'))
    })
     
    builder.factory('class-c', container => {
      return new ClassC(container.get('class-a'), container.get('class-b'))
    })
     
    const container = builder.build()

    Next use the container to load the services. All services are singletons inside the container:

    const classA = container.get('class-a')
    const classB = container.get('class-b')
    const classC = container.get('class-c')

    Install

    npm i js-service-container

    DownloadsWeekly Downloads

    9

    Version

    0.0.1

    License

    MIT

    Unpacked Size

    25.4 kB

    Total Files

    42

    Last publish

    Collaborators

    • avatar