@sixphere/diwrapper

Dependency injection lightweight library.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@sixphere/diwrapper
001.0.35 years ago5 years agoMinified + gzip package size for @sixphere/diwrapper in KB

Readme

Sixphere - Dependency Injector Wrapper
!Versionversion-badgeversion-url !Node versionnode-version-badgenode-version-url !MIT Licensemit-license-badgemit-license-url
!Downloadsdownloads-badgedownloads-url !Total downloadstotal-downloads-badgedownloads-url
!Packagephobiapackagephobia-badgepackagephobia-url !Bundlephobiabundlephobia-badgebundlephobia-url
Dependency injection lightweight library that allows you inject any service instance in any class in a fast and easy way.

Install

npm install '@sixphere/diwrapper' --save

How to use?

The centerpiece of the dependency injector is the __inject method. Your class must implement a method with this name and the needed arguments. The library use this method to inject the builded instances.
// dummy-component.js
class DummyComponent {
    
    //...
    
    __inject(dummyService1, dummyService2) {
        this.dummyService1 = dummyService1
        this.dummyService2 = dummyService2
    }

    //...
    
}

Bind dependencies

Import the dependency injector wrapper.
import { DIWrapper } from '@sixphere/diwrapper'

Specify the class and his dependecies.
// index.js
let ComposedDummyComponent = DIWrapper.for(DummyComponent).bind([
                                { constructor: DummyService1, args: [] }, 
                                { constructor: DummyService2, args: [] },
                            ])

License

MIT Licensemit-license-url © 2019 Sixphere