@sixphere/diwrapper

1.0.3 • Public • Published

Sixphere - Dependency Injector Wrapper

Version Node version MIT License

Downloads Total downloads

Packagephobia Bundlephobia


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 License © 2019 Sixphere

Package Sidebar

Install

npm i @sixphere/diwrapper

Weekly Downloads

18

Version

1.0.3

License

MIT

Unpacked Size

6.53 kB

Total Files

5

Last publish

Collaborators

  • ferjimriv
  • sixphere-codelovers